ProgrammingVery hardProduct company OA · GATE CS

Which of these statements about C (not C++) are true? (i) A const int variable at file scope is a constant expression, so it can size a file-scope array. (ii) With const int *p, the pointer p itself can be changed. (iii) A variable can be declared both const and volatile. (iv) Writing to an object that was defined const, after casting the const away, is undefined behaviour.

  1. A. (ii), (iii) and (iv) only
  2. B. (i), (ii) and (iv) only
  3. C. All four
  4. D. (ii) and (iv) only

Correct answer: A. (ii), (iii) and (iv) only

(i) holds in C++ but not in C, where a const variable is not an integer constant expression; use an enum or #define. const volatile is legal and common for read-only hardware registers. const int *p protects the target, not p.

More C Programming questions

Exams that ask this topic