ProgrammingHardProduct company OA · GATE CS
Assume 4-byte int. What is printed?
Assume 4-byte int. What is printed?
struct Msg { int len; char data[]; };
struct Msg *m = malloc(sizeof *m + 10);
printf("%zu", sizeof *m);- A. 14
- B. 8
- C. 5
- D. 4
Correct answer: D. 4
data[] is a C99 flexible array member: it adds no size of its own, so sizeof(struct Msg) is just the int (4 here). The extra 10 bytes from malloc are what data uses, but sizeof is fixed at compile time and never sees them.
More C Programming questions
- What is printed? c printf("%zu %zu", sizeof("ab" "cd"), strlen("ab0cd"));
- What is printed? c int n = printf("%d", printf("%s", "abc")); printf(" %d", n);
- What is printed? c int f(int n, int b) { return n < b ? 1 : 1 + f(n / b, b); } int main(void) { printf("%d %d %d", f(1000, 2), f(1000…
- What is printed? c const char s = "education"; int v = 0, o = 0; for (; s; s++) switch (s) { case 'a': case 'e': case 'i': case 'o': case…
- Which of these functions return a pointer that is still valid to read after the function returns? c char f1(void) { char s[] = "hi"…
- Assume 32-bit unsigned int. What is printed? c unsigned int x = 65536; printf("%u %u", x x, x (x - 1) / 2);