+ 4

What's Wrong?

What is the output of this code? #include<iostream> using namespace std; #define SQURE(x) x*x int main() { int s=3, t; t=SQURE(s+1); cout<<t; } Community Declined one, what's wrong in this? this is one of a simple & easy Question to check your knowledge about macros.

25th Jul 2017, 1:42 AM
Anil Khatri
Anil Khatri - avatar
12 Antworten
+ 3
@BangTu well squre doesn't necessarily mean square, right? all in all, the op wonder why this perfect question, which tests players' knowledge about macro, is not accepted. The op knows the answer is 7 and expect it as correct answer too. well, rethinking it again, maybe the reason of declination is because a high percentage of players will get this wrong.
25th Jul 2017, 12:24 PM
Veii Xhen
Veii Xhen - avatar
+ 4
You should change to: #define SQURE(x) (x)*(x)
25th Jul 2017, 4:46 AM
Bàng Tứ Cường
Bàng Tứ Cường - avatar
+ 4
So, the problem is when compiling, SQURE(s+1) is replaced with s+1*s+1 (without the brackets).
25th Jul 2017, 7:19 AM
Bàng Tứ Cường
Bàng Tứ Cường - avatar
+ 4
awesome challenge man I'll give you upvote if i come across it our challenge quality is certainly improving
25th Jul 2017, 5:00 PM
‎ ‏‏‎Anonymous Guy
+ 3
What's wrong here is the macro doesn't result in a "square". What's the author expect is SQURE(x) will result in x*x (square). In this case, it is expected that SQURE(s+1) = SQURE(4) = 4*4 = 16, but as my previous answer pointed out, the compiler will replace SQURE(s+1) with s+1*s+1 = 3 + 1*3 + 1 = 7.
25th Jul 2017, 8:32 AM
Bàng Tứ Cường
Bàng Tứ Cường - avatar
+ 3
@Veii Thanks Man you Got me😊 @BangTu you are totally correct in your ways and that show your clear knowledge at Macros But here we are testing that only via Quiz , I asked this question because it was declined by community! Thanks Man!! Hope we will take care of good questions. & Yes Thanks @Sreejith☺
26th Jul 2017, 11:45 AM
Anil Khatri
Anil Khatri - avatar
+ 2
judging from an open angle, maybe it is too easy compared to other questions. Maybe you can add a class and increase its complexity by a little
25th Jul 2017, 2:44 AM
Veii Xhen
Veii Xhen - avatar
+ 2
ok what should be the answer im getting 7 after compilation
25th Jul 2017, 3:05 AM
‎ ‏‏‎Anonymous Guy
+ 2
@Sreejith that's the trick in the question, @BangTu you typed right but we are answering quizzes aren't we?
25th Jul 2017, 6:56 AM
Anil Khatri
Anil Khatri - avatar
+ 2
Exactly!! @BangTu, You Got me! But again I'm saying it's a quiz and you need to predict the output!! So what's wrong in here!!
25th Jul 2017, 7:49 AM
Anil Khatri
Anil Khatri - avatar
+ 1
sorry, I didn't get your idea in the first place, my bad. This should be a perfect quiz for challenge.
26th Jul 2017, 1:41 PM
Bàng Tứ Cường
Bàng Tứ Cường - avatar
0
Again Rejected haha😄
5th Aug 2017, 2:22 PM
Anil Khatri
Anil Khatri - avatar