ProgrammingHardTCS NQT · Infosys
char a[] = "hi"; char b[] = "hi"; What does a == b evaluate to?
- A. 1
- B. undefined
- C. 0
- D. depends on the compiler
Correct answer: C. 0
Distinct array objects have distinct addresses, so comparing them gives 0. Use strcmp for string equality, not ==.
More C Programming questions
- What does printf("%d", '0' < '9') print?
- What does printf("%d", 6 % 4 2) print?
- Which expression computes ceil(a / b) for positive int a = 7 and b = 3 using integer arithmetic, written as ((a + b - 1) / b)?
- int a[3][4]; for (int i = 0; i < 3; i++) for (int j = 0; j < 4; j++) a[i][j] = i 4 + j; printf("%d", (&a[0][0] + 7)); What is printed?
- With int a[3][4] (4-byte int, row-major), what is the value of (int )&a[1][0] - (int )&a[0][0]?
- With int a[3][4] (4-byte int) and int (p)[4] = a, what is (char )(p + 2) - (char )p?