ProgrammingModerateTCS NQT · Infosys
What is printed? Assume a pointer is 8 bytes and a char array of length 10 is passed to f.
What is printed? Assume a pointer is 8 bytes and a char array of length 10 is passed to f.
#include <stdio.h>
void f(char s[]) {
printf("%zu", sizeof s);
}
int main(void) {
char b[10];
f(b);
}- A. 10
- B. 9
- C. 1
- D. 8
Correct answer: D. 8
A parameter declared as char s[] is really a char *, so sizeof s is the pointer size, 8 bytes here. The array length 10 is not passed.
More C Programming questions
- What is printed? c #include <stdio.h> int main(void) { printf("%d", 2 3 + 4 % 3 == 0 ? 1 : 2); }
- What is printed? Assume a 32-bit unsigned int. c #include <stdio.h> int main(void) { unsigned x = 1; for (int i = 0; i < 31; i++) x <<= 1…
- What is printed? c #include <stdio.h> int main(void) { int i; int a[5] = {0}; for (i = 0; i < 5; i++) a[i] = i i; printf("%d", a[4]…
- How many placements of 4 queens on a 4 by 4 board have no two queens attacking each other? The program counts them by backtracking. What…
- What is printed? c #include <stdio.h> int der(int n) { if (n == 0) return 1; if (n == 1) return 0; return (n - 1) (der(n - 1) + der(n…
- How many subsets of {1, 2, 3, 4, 5} sum to 6? Compute with this recursive program. c #include <stdio.h> int v[5] = {1, 2, 3, 4, 5}; int…