ProgrammingModerate
char *names[] = {"x", "yy", "zzz"}; printf("%zu", strlen(names[2])); What is printed?
- A. 3
- B. 1
- C. 2
- D. 4
Correct answer: A. 3
names[2] points at "zzz", and strlen counts its 3 characters but not the terminator. 4 adds the '\0', and 2 reads names[1] by an off-by-one slip.
More C Programming questions
- int a[4] = {4, 3, 2, 1}; int s = 0; for (int i = 0; i < 4; i++) s = s 10 + a[i]; printf("%d", s); What is printed?
- int i = 1; int s = 0; while (i <= 4) s += i++; printf("%d", s); What is printed?
- int n = 0; do { n += 2; } while (n < 7); printf("%d", n); What is printed?
- unsigned char c = 0; c -= 1; printf("%d", c); What is printed?
- int m = 2147483647; printf("%d", m / 2); What is printed with a 32-bit int?
- How many subsets of the bit positions of mask 22 (binary 10110) are visited, counting the empty subset? Compute with this program. c…