+ 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<

7th Mar 2017, 6:53 AM
Mr.Robot
Mr.Robot - avatar
5 Answers
+ 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
7th Mar 2017, 7:05 AM
Burey
Burey - avatar
+ 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
7th Mar 2017, 7:09 AM
Mr.Robot
Mr.Robot - avatar
+ 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
7th Mar 2017, 7:21 AM
Burey
Burey - avatar
+ 6
You can do this #include <iostream> using namespace std; #define sqr(x,y) ((x*x)+(2*x*y)+(y*y)) int main() { cout<
7th Mar 2017, 7:11 AM
Prabhakar Dev
Prabhakar Dev - avatar
+ 6
I think I didn't understand the question
7th Mar 2017, 7:14 AM
Prabhakar Dev
Prabhakar Dev - avatar