ProgrammingHardWipro · Cognizant pattern
Assume 32-bit int. What is printed?
Assume 32-bit int. What is printed?
int x = 1;
int y = 2;
int z = 3;
int result = x + y == z;
printf("%d", result);- A. Compile-time error: + and == cannot appear in the same expression without parentheses
- B. 0
- C. 1
- D. 6
Correct answer: C. 1
+ has higher precedence than ==, so x + y == z parses as (x + y) == z, i.e. (1+2) == 3, i.e. 3 == 3, which is true, giving result = 1 (not the sum 6, and not treating '==' as binding first).
More C Programming questions
- What happens when this runs? c int divide(int result, int a, int b) { if (b == 0) return -1; result = a / b; return 0; } int main(void) {…
- Assume 32-bit int. What is printed? c int x = 3; int result = x++ + x++ - x++; printf("%d", result); printf(" valid: %s", "no, undefined…
- What is printed? c int main(void) { int a[3] = {1, 2, 3}; int b[3] = {1, 2, 3}; printf("%d", a == b); }
- What is printed? c int main(void) { char a[] = "test"; char b[] = "test"; printf("%d %d", a == b, strcmp(a, b) == 0); }
- What is printed? c int main(void) { int x = 100; long y = x; long long z = y 1000000000L; printf("%lld", z); }
- What is printed? c int main(void) { int n = 5; int result = 1; int i = 1; while (i <= n) { result = i; i++; } printf("%d", result); }