ProgrammingVery hardProduct company OA
What is printed?
What is printed?
int a = 5, b = 10;
int r = a & b == 10;
printf("%d", r);- A. 0, since (a & b) == 10 is computed first
- B. 15, treating & like addition
- C. Compilation error: ambiguous precedence
- D. 1, since == binds tighter than bitwise &, giving a & (b == 10)
Correct answer: D. 1, since == binds tighter than bitwise &, giving a & (b == 10)
A classic precedence trap: relational/equality operators bind TIGHTER than bitwise &. So a & b == 10 parses as a & (b == 10) = 5 & (10==10) = 5 & 1. In binary, 5 is 0101 and 1 is 0001; ANDing gives 0001 = 1. The naive but wrong reading (a & b) == 10 would instead give (5&10)==10 = 0==10 = 0.
More C Programming questions
- 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…
- What is printed (64-bit, 4-byte int)? c int a[5] = {1,2,3,4,5}; int p = a + 5; printf("%d", (p - 1) + (a + 0));
- What is printed? c int x = 100; void f(int p) { int y = 200; p = &y; } int main() { int p = &x; f(p); printf("%d", p); }
- What is printed? c int arr[3] = {1, 2, 3}; int (p)[3] = &arr; printf("%d %d", (p)[1], (p + 2));