ProgrammingModerate
char s[3] = "ab"; printf("%zu", sizeof s); What is printed?
- A. 3
- B. 2
- C. 4
- D. 5
Correct answer: A. 3
The array is declared with three elements, so sizeof is 3 regardless of the two characters and terminator in it.
More C Programming questions
- char a = "xy"; char b = a; b[0] = 'z'; printf("%s", a); What is printed?
- char buf[8] = "12"; int n = strlen(buf); printf("%d %d", n, (int)sizeof buf - n); What is printed?
- char z[6] = "ab0cd"; printf("%zu", strlen(z)); What is printed?
- 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?