ProgrammingHardTCS NQT · Infosys pattern
What is printed?
What is printed?
int a = 5;
int b = a++, c = ++a;
printf("%d %d %d", a, b, c);- A. 6 5 6
- B. 7 5 7
- C. 7 6 7
- D. 6 6 7
Correct answer: B. 7 5 7
The comma in a declarator list separates full declarations with a sequence point between them: b = a++ reads 5 then increments a to 6; c = ++a increments a to 7 then reads 7. Final state: a=7, b=5, c=7.
More C Programming questions
- What is printed? c int x = 2, y = 3, z = 4; int r = x + y == z || x y == z + 2; printf("%d", r);
- What is printed? c int a = 7; int r = a % 3 + 2 a / 7; printf("%d", r);
- What is printed? c int a = 5, b = 10; int r = a & b == 10; printf("%d", r);
- What is printed? c char arr[] = {"alpha", "beta", "gamma"}; char p = arr; printf("%s %c %s", (p + 1), ((p + 2) + 1), p);
- What is printed? c int x = 10; int p = &x; int pp = &p; pp = 20; pp = NULL; printf("%d %d", x, (p == NULL));
- What is printed? c void modify(int arr, int n) { for (int i = 0; i < n; i++) arr[i] = 2; } int main() { int a[] = {1, 2, 3}; int p = a…