ProgrammingHardHCL · Tech Mahindra pattern

What is printed?

What is printed?
int main(void) {
    char a[] = "test";
    char b[] = "test";
    printf("%d %d", a == b, strcmp(a, b) == 0);
}
  1. A. 1 1
  2. B. 0 0
  3. C. 1 0
  4. D. 0 1

Correct answer: D. 0 1

a and b are two SEPARATE char arrays (each its own copy of the string), so a==b compares distinct addresses: false (0). strcmp compares their CONTENTS character by character, which are identical: returns 0, so `== 0` is true (1).

More C Programming questions

Exams that ask this topic