ProgrammingHardWipro · Cognizant pattern

What is printed?

What is printed?
int main(void) {
    int a[3] = {1, 2, 3};
    int b[3] = {1, 2, 3};
    printf("%d", a == b);
}
  1. A. 3
  2. B. 0
  3. C. 1
  4. D. Compilation error: cannot compare arrays with ==

Correct answer: B. 0

a and b decay to pointers to their own separate, distinct memory regions; `a == b` compares these two different addresses, which are never equal even though the arrays hold identical contents: 0 (false).

More C Programming questions

Exams that ask this topic