ProgrammingHard
char z[6] = "ab\0cd"; printf("%zu", strlen(z)); What is printed?
- A. 4
- B. 5
- C. 3
- D. 2
Correct answer: D. 2
The embedded \0 terminates the string after ab, so strlen is 2 even though the array holds more bytes.
More C Programming questions
- int n = sprintf(NULL, "%s", "hello"); printf("%d", n); What is printed?
- int m = malloc(3 sizeof m); for (int i = 0; i < 3; i++) m[i] = malloc(4 sizeof m); / later / for (int i = 0; i < 3; i++) free(m[i])…
- int m[2][5]; printf("%zu", sizeof m[0]); What is printed on a platform with 4-byte int?
- int r = 2, c = 5; int m[r][c]; printf("%zu", sizeof m); What is printed on a platform with 4-byte int (C99 variable-length array)?
- int m[3][4] = {{1, 2, 3, 4}, {5, 6, 7, 8}, {9, 10, 11, 12}}; int (row)[4] = m; printf("%d", ((row + 2))[3]); What is printed?
- char g[2][3] = {"ab", "cde"}; printf("%c", g[1][2]); What is printed?