+ 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.
12 Respostas
+ 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.
+ 4
You should change to:
#define SQURE(x) (x)*(x)
+ 4
So, the problem is when compiling, SQURE(s+1) is replaced with s+1*s+1 (without the brackets).
+ 4
awesome challenge man
I'll give you upvote if i come across it
our challenge quality is certainly improving
+ 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.
+ 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âș
+ 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
+ 2
ok what should be the answer
im getting 7 after compilation
+ 2
@Sreejith that's the trick in the question, @BangTu you typed right but we are answering quizzes aren't we?
+ 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!!
+ 1
sorry, I didn't get your idea in the first place, my bad. This should be a perfect quiz for challenge.
0
Again Rejected hahađ