Top

Discussion

Comment on the output of this C code?

#include 
    void main()
    {
        int const k = 5;
        k++;
        printf("k is %d", k);
    }

 

  • A.k is 6
  • B.Error due to const succeeding int
  • C.Error, because a constant variable can be changed only twice
  • D.Error, because a constant variable cannot be changed

Answer: D

Constant variable has to be declared and defined at the same time. Trying to change it results in an error.

Output:
$ cc pgm12.c
pgm12.c: In function ‘main’:
pgm12.c:5: error: increment of read-only variable ‘k’

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

Post your comment