ProgrammingModerateTCS NQT · Accenture
What is printed by sizeof?
What is printed by sizeof?
#include <stdio.h>
int main(void) {
char t[] = "a\0b\0c";
printf("%zu", sizeof t);
}- A. 3
- B. 4
- C. 5
- D. 6
Correct answer: D. 6
The array holds five characters, the embedded nulls included, plus the terminating null, so sizeof t = 6. strlen would stop at the first null and give 1.
More C Programming questions
- What is printed? c #include <stdio.h> int main(void) { int a[] = {10, 20, 30}; int p[] = {a, a + 1}; printf("%d", p[1] + (p + 2)); }
- What is printed? c #include <stdio.h> int main(void) { printf("%d", 1 << 30 >> 28); }
- What is printed? A sorted int array {1, 3, 5, 7} is searched with bsearch for the key 6. c #include <stdio.h> #include <stdlib.h> int…
- How many subsets of {1, 2, 3, 4, 5} sum to exactly 10? Compute with this program. c #include <stdio.h> int main(void) { int c = 0; for…
- What is printed? c #include <stdio.h> #include <stdlib.h> int cmp(const void a, const void b) { int x = (const int )a, y = (const int )b…
- What is printed? c #include <stdio.h> int main(void) { unsigned s = 0; for (unsigned b = 1; b; b <<= 1) s += 1; printf("%u", s); }