ProgrammingModerateProduct-company MCQ pattern
What is printed?
What is printed?
char s[] = "abc\0def";
printf("%zu %zu", sizeof(s), strlen(s));- A. 8 3
- B. 7 7
- C. 8 7
- D. 4 3
Correct answer: A. 8 3
The array keeps all 7 written characters (a b c \0 d e f) plus the automatic terminating '\0', so sizeof is 8. strlen stops at the first '\0', after abc, giving 3.
More C Programming questions
- What is printed? c printf("%zu", strlen("atbn"));
- What is printed? c int a = -1, b = 1; if (a > 0) if (b > 0) printf("X"); else printf("Y"); printf("Z");
- What is printed? c int x = 4; if (x & 1 == 0) printf("even"); else printf("odd");
- What is printed? c int f(int n) { static int s = 0; s += n; if (n > 0) f(n - 1); return s; } ... printf("%d ", f(3)); printf("%d", f(3));
- What is printed? c printf("%d", 2 + 3 << 1 & 7);
- How many of these are correct in C? (i) A global variable without an initialiser starts as 0. (ii) A static local variable is initialised…