ProgrammingModerateWipro · Capgemini pattern
What is printed?
What is printed?
int a = 5, b;
b = a++ + 10;
printf("%d %d", a, b);- A. 5 15
- B. 5 16
- C. 6 16
- D. 6 15
Correct answer: D. 6 15
a++ gives the old value 5 to the expression and then increments a, so b = 5 + 10 = 15 and a = 6. 16 would need the pre-increment ++a.
More C Programming questions
- What is printed? c char s[] = "placement"; printf("%zu %zu", sizeof(s), strlen(s));
- What is printed? c int arr[] = {10, 20, 30, 40}; int p = arr; p += 2; printf("%d", p);
- What does f(4096) return? c int f(int n) { if (n == 0) return 0; return n % 10 + f(n / 10); }
- What is printed? c printf("%d %d %d", 12 & 10, 12 | 10, 12 ^ 10);
- What is printed? c #define SQUARE(x) x x printf("%d", SQUARE(2 + 3));
- What is printed when count() is called three times in a row? c void count(void) { static int c = 0; c++; printf("%d ", c); }