ProgrammingModerateWipro · Capgemini pattern
What is printed?
What is printed?
char s[] = "hello";
char *p = s;
printf("%zu %zu %zu", strlen(s), sizeof(s), sizeof(p)); /* 64-bit system */- A. 5 5 8
- B. 5 6 8
- C. 5 6 6
- D. 6 6 8
Correct answer: B. 5 6 8
strlen stops at the terminator (5). The array holds 5 characters plus '\0' (6 bytes). p is a pointer, so sizeof(p) is the pointer size, 8 on a 64-bit system – not the string length.
More C Programming questions
- What is printed? c int i = 10, c = 0; do { c++; i++; } while (i < 5); printf("%d %d", i, c);
- What is printed? c int i, j, s = 0; for (i = 0, j = 10; i < j; i += 2, j--) s += j - i; printf("%d %d %d", i, j, s);
- What is printed? c unsigned int u = -16; / 32-bit unsigned int / printf("%d %u %d", 1 << 4, u >> 28, -16 / 4);
- What is printed? c int a = 5, b, c; b = a > 3 ? 10 : 20; c = (b == 10) ? a + b : 0; printf("%d %d %d", a, b, c);
- What is printed? c struct A { char c; int i; char d; }; struct B { int i; double d; }; struct C { char c; double d; char e; }; printf("%zu…
- What is printed? c char s = "hello"; printf("%c %c %c", s[1], 4[s], ("abc" + 2));