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.
- A. (ii), (iii) and (iv) only
- B. (i), (ii) and (iv) only
- C. All four
- 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
- Which of these is NOT allowed for a variable declared with the register storage class in C?
- What does p(5) print? c void p(int n) { if (n <= 0) return; p(n - 2); printf("%d", n); p(n - 3); }
- Which statement about this C declaration is true? c char a[5] = "hello";
- What is printed? c #define CUBE(x) ((x) (x) (x)) int n = 0; int f(void) { n++; return 2; } int main(void) { int r = CUBE(f()); printf("%d…
- What is printed? c unsigned char rotl(unsigned char v, int k) { return (unsigned char)(v << k | v >> (8 - k)); } int main(void) {…
- With int a[3], p = a; which statement fails to compile?