ProgrammingHardGATE CS · TCS NQT
What is printed? Assume int is 4 bytes.
What is printed? Assume int is 4 bytes.
#include <stdio.h>
int main(void) {
int i = 1;
size_t n = sizeof(i++);
printf("%d %zu", i, n);
}- A. 1 1
- B. 2 4
- C. 1 4
- D. 2 1
Correct answer: C. 1 4
The operand of sizeof is not evaluated, so i stays 1, while sizeof(int) is 4. Expecting the increment to happen is the usual trap.
More C Programming questions
- How many factors of 2 does 100! contain? Compute with this program. c #include <stdio.h> int main(void) { int c = 0; for (int i = 2; i <=…
- What is printed? c #include <stdio.h> #include <string.h> int main(void) { char s[] = "stressed"; char a = s, b = s + 7; while (a < b) {…
- What is printed? c #include <stdio.h> unsigned parse(const char s) { unsigned n = 0; while (s) n = n 10 + (unsigned)(s++ - '0'); return n…
- What is printed? c #include <stdio.h> int main(void) { long long x = (1LL << 40) + 5; printf("%d", (int)(x & 0xFFFFFFFFLL)); }
- What is printed? Assume int is 4 bytes. c #include <stdio.h> int main(void) { printf("%zu", sizeof('a')); }
- What is printed? c #include <stdio.h> int main(void) { printf("%d", ~5 & 0xF); }