ProgrammingModerateCognizant GenC · C
What is printed?
What is printed?
char s[] = "hello";
s[2] = '\0';
printf("%zu %zu %s", sizeof s, strlen(s), s + 3);- A. 6 2 lo
- B. 6 5 lo
- C. 5 2 lo
- D. 6 2 llo
Correct answer: A. 6 2 lo
sizeof counts the whole array (6 bytes including the original terminator); strlen stops at the new '\0' (2); s + 3 still points at "lo".
More C Programming questions
- What is printed? c unsigned char c = 200; c += 100; printf("%d", c);
- What is printed? c int f(void) { static int c = 0; return ++c; } int main(void) { int s = 0; for (int i = 0; i < 4; i++) s += f() i…
- What is printed? c #define SQ(x) x x printf("%d", SQ(2 + 1) + SQ(3));
- What is printed? c int a = 3, b = 4; printf("%d", a < b ? a > 1 ? 10 : 20 : 30);
- What is printed? Assume a 4-byte int. c int m[3][4]; printf("%zu %zu %zu", sizeof(m[0]), sizeof(m), sizeof m);
- What is printed? c int a[2][3] = {{1, 2, 3}, {4, 5, 6}}; int p = &a[0][0]; printf("%d %d %d", (p + 4), (a[1] + 2), (a)[2]);