C Logical Operators
Please Log In for full access to the web site.
Note that this link will take you to an external site (https://shimmer.mit.edu) to authenticate, and then you will be redirected back to this page.
Order of precedence of binary operators
To answer the following questions, make sure to take the order of precedence of the binary operators into consideration.
In this exercise, we are going to further explore logical operators to better understand exactly how they behave in C. For the following exercises, you will be given snippets of C code and asked to evaluate the results of each in decimal.
What is the value of a?int a = 5 | 6 >> 1;
What is the value of b?int b = 8 ^ 5 & 9 | 3;
What is the value of c?int c = !0 && 1 || 5 || 3 && 0;
What is the value of d?int d = 2 + 3 << 4 / 2 == 7 ^ 5 * 2 | 4;
Given that the following code:
int a = 2;
int b = a++ + a;
printf("a = %d, b = %d\n", a, b);
will print a = 3, b = 5, answer the following question.
What is the value of f?int e = 6;
int f = e++ - 2 + e;