ProgrammingHardProduct-company MCQ pattern
What is printed?
What is printed?
/* LP64: 4-byte int, 8-byte long, 4-byte float */
char c = 'a';
short s = 2;
printf("%zu %zu %zu %zu", sizeof(c), sizeof(c + c), sizeof(s * 2L), sizeof(c ? s : 1.0f));- A. 1 1 8 2
- B. 1 4 8 4
- C. 1 4 4 4
- D. 1 4 8 2
Correct answer: B. 1 4 8 4
sizeof looks only at the TYPE of the expression. c + c promotes both chars to int, so it is 4. s * 2L converts s to long, so 8 on LP64. The conditional operator's result type comes from both branches after the usual arithmetic conversions — short and float give float (4) — regardless of which branch would be taken.
More C Programming questions
- What is printed? c / x86-64 LP64: natural alignment (double 8, int 4, short 2) / struct X { char a[5]; double d; char e; }; struct Y {…
- What is printed? c void p(const char s) { if (!s) return; putchar(s); p(s + 2); putchar(s); } int main(void) { p("abcdef"); }
- What is printed? c / LP64: 4-byte int, 8-byte pointers / int a[2][3] = {{1, 2, 3}, {4, 5, 6}}; int (p)[3] = a; printf("%d %d %zu %zu"…
- What is printed? c int i, c = 0; for (i = 0; i < 6; i++) if (i % 2 == 0 || ++c > 1) c += 10; printf("%d %d", i, c);
- What is printed? c / 16-bit unsigned short, 32-bit int and unsigned / unsigned short a = 3, b = 5; printf("%d %u %d", a - b, 3u - 5u…
- What is printed? c #define ABS(x) x < 0 ? -x : x printf("%d %d", ABS(2 - 5), ABS(-4) 2);