Top

Discussion

What is the output of this C code?

#include 
    #define a 10
    int main()
    {
        const int a = 5;
        printf("a = %d\n", a);
    }

 

  • A.a = 5
  • B.a = 10
  • C.Compilation error
  • D.Runtime error

Answer: C

The #define substitutes a with 10 leaving no identifier and hence compilation error.

Output:
$ cc pgm3.c
pgm3.c: In function ‘main’:
pgm3.c:5: error: expected identifier or ‘(’ before numeric constant

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

Post your comment