ProgrammingModerateTCS NQT · Infosys pattern
What is printed?
What is printed?
int i = 5;
size_t s = sizeof(i++);
printf("%zu %d", s, i); /* 4-byte int */- A. 4 5
- B. 4 6
- C. 8 5
- D. 5 5
Correct answer: A. 4 5
sizeof is evaluated at compile time from the type of its operand; the expression i++ is never executed (except for variable-length arrays), so i stays 5.
More C Programming questions
- What is printed? c char names[] = {"Ann", "Bob", "Cy"}; printf("%c %s %zu", names[1][0], names[2], strlen(names[0]));
- What is printed? c int n = 40; / binary 101000 / printf("%d %d %d", n & (n - 1), n & -n, (n & (n - 1)) == 0);
- What is printed? c int a[] = {3, 1, 4, 1, 5}; int sum(int n) { return n == 0 ? 0 : a[n - 1] + sum(n - 1); } int main(void) { printf("%d"…
- Assume a 64-bit LP64 ABI (4-byte int, 8-byte pointers and double, natural alignment). What is printed? c int a[3][4] = {{1, 2, 3, 4}, {5…
- Assume 32-bit int and two's complement. What is printed? c unsigned char a = 0x0F; unsigned char b = ~a; printf("%d %d %d %d %zu", ~a ==…
- Assume 32-bit int and 64-bit long long. What is printed? c int n = -1; unsigned int len = 3; long long big = -1; printf("%d %d %d %d", n <…