ProgrammingHardGATE CS
What is printed?
What is printed?
#include <stdio.h>
int main(void) {
int a = 0, b = 1, c = 2;
int r = (a++ && b++) || (c-- && a--);
printf("%d %d %d %d", r, a, b, c);
return 0;
}- A. 1 0 2 1
- B. 1 0 1 1
- C. 1 1 1 1
- D. 0 0 2 1
Correct answer: B. 1 0 1 1
a++ yields 0 (a becomes 1), so && skips b++ and the left side is 0. The right side of || is then evaluated: c-- yields 2 (c becomes 1), which is true, so a-- runs (yields 1, a becomes 0). r = 1, a = 0, b = 1, c = 1.
More C Programming questions
- What is printed? Assume int occupies 4 bytes. c #include <stdio.h> int main(void) { int i = 5; sizet n = sizeof(i++) + sizeof(i = 100)…
- What is printed? Assume int is 32 bits and unsigned char is 8 bits. c #include <stdio.h> int main(void) { unsigned char c = 0x0F…
- What is printed? Assume int and unsigned int are 32 bits. c #include <stdio.h> int main(void) { int a = -1; unsigned int b = 1; printf("%d…
- What is the value printed? Assume unsigned int is 32 bits. c #include <stdio.h> int main(void) { unsigned x = 0xB6D9 ^ 0x00FF; int n = 0…
- What is printed? c #include <stdio.h> #define MAX(a, b) ((a) > (b) ? (a) : (b)) int main(void) { int i = 3, j = 5; int m = MAX(i++, j++)…
- What is printed? c #include <stdio.h> int f(int n) { static int c = 0; c++; if (n >= 2) { f(n - 1); f(n - 2); } return c; } int main(void)…