ProgrammingHardHCL · Tech Mahindra · C placement

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[3] = {1, 2, 3}; int b[3]; for (int i = 0; i < 3; i++) b[i] = a[i]; b[0] = 99; printf("%d %d", a[0], b[0]); return 0; }

  1. A. 99 1
  2. B. 1 99
  3. C. 99 99
  4. D. 1 1

Correct answer: B. 1 99

Copying element by element creates an independent array b; changing b[0] afterward does not affect a[0].

More C Programming questions

Exams that ask this topic