Top

Discussion

What is the output of this C code?

#include 
    int main()
    {
        const int p;
        p = 4;
        printf("p is %d", p);
        return 0;
    }

 

  • A.p is 4
  • B.Compile time error
  • C.Run time error
  • D.p is followed by a garbage value

Answer: B

Since the constant variable has to be declared and defined at the same time, not doing it results in an error.

Output:
$ cc pgm10.c
pgm10.c: In function ‘main’:
pgm10.c:5: error: assignment of read-only variable ‘p’

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

Post your comment