// Community Downvotes | SoloLearn: Learn to code for FREE!

+7

// Community Downvotes

//Declined due to community downvotes. Please review and resubmit What is the output of this code? #define sqr(x) (x*x) int main() { cout<<sqr(5+2); } Seriously ? Why this code has more downvotes when it doesn't have complicated maths. If you know the concept of #define this question isn't a problem at all. But why down voting it :/ People will like cout<<1+2; question but not like this type of questions.Solo Learn should not decline quiz based on likes :/ P.s: My English isn't good though!

3/7/2017 6:53:43 AM

Mr.Robot

5 Answers

New Answer

+7

for starters, just checked and it doesn't work well i expected the result 49 and got 17 (5*2+5+2 perhaps???) o_O only when used with another set of brackets sqr((5+2)) did i get what i expected

+7

@burey , In c++ , #define used to replace the parameter before the compiler executes. So in the program , #define sqr(x) (x*x) will replace the (x*x) in sqr(x) before compiler executes so sqr(5+2) = (5+2*5+2) = 17 Your answer 49 will come if the #define sqr(x) (x)*(x) is defined like this way. I hope you understood. :D

+7

understood now thanks could be that many of those who downvoted expected the same answer as me and when didn't get it just treated the quiz as faulty

+6

You can do this #include <iostream> using namespace std; #define sqr(x,y) ((x*x)+(2*x*y)+(y*y)) int main() { cout<<sqr(5,2); return 0; }

+6

I think I didn't understand the question