ProgrammingVery hardTCS NQT · Infosys · Product Company SDE

What is the output of this C program (assume a typical 64-bit platform: int 32 bits, long and pointers 64 bits, double 8 bytes, structs aligned to their widest member with no packing pragma)? #include <stdio.h> int main(void) { int a = 5; int *const p = &a; *p = 50; printf("%d", a); return 0; }

  1. A. 50
  2. B. 0
  3. C. 5
  4. D. Compilation error

Correct answer: A. 50

int *const p means p itself cannot be repointed, but the pointee is still mutable through *p, so *p = 50 legally changes a to 50.

More C Programming questions

Exams that ask this topic