Machine-translated by Google. Questions are authored in English.
Top

Discussion

What will be the output of the program?

#include <stdio.h>
#define SQR(x)(x*x)

int main()
{
    int a, b=3;
    a = SQR(b+2);
    printf("%d\n", a);
    return 0;
}

 

  • A.25
  • B.11
  • C.Error
  • D.Garbage value

Answer: B

Correct answer: 11

The macro body parenthesises the whole expression but not the parameter, so SQR(b+2) becomes (b+2*b+2):

\[ 3 + 6 + 2 = 11 \]

Only ((x)*(x)) would give the intended \(5^2 = 25\).

No comment is present. Be the first to comment.
Loading…

Post your comment

Please log in or register to post a comment.