ProgrammingHardTCS NQT · Infosys

On an LP64 system (8-byte pointers), what is printed?

On an LP64 system (8-byte pointers), what is printed?
char a[] = "cat", *b = "cat";
printf("%d %d", strcmp(a, b) == 0, sizeof(a) == sizeof(b));
  1. A. 0 0
  2. B. 1 0
  3. C. 1 1
  4. D. 0 1

Correct answer: B. 1 0

strcmp compares contents, which match, so the first test is 1. a is an array of 4 chars (sizeof 4) while b is a pointer (sizeof 8), so the second test is 0. Arrays and pointers behave alike in expressions but not under sizeof.

More C Programming questions

Exams that ask this topic