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; }
- A. 99 1
- B. 1 99
- C. 99 99
- 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
- In C, sizeof(char) is:
- Which storage class makes a local variable keep its value between calls to the function?
- The end of a C string is marked by:
- Which declaration makes p a pointer to an int?
- A line such as #include <stdio.h> is processed by:
- Which printf format specifier is meant for printing a pointer value (an address)?