Study Questions #4 - 50-85 Flashcards
Show the output produced by the following program fragment. int i = 1; int j = 2; i = + - + - + - j; printf("%d %d\n", i, j);
-2 2
Show the output produced by the following program fragment. int i = 1; int j = 2; i = - + - + - ++ j; printf("%d %d\n", i, j);
-3 3
Show the output produced by the following program fragment. int i = 1; int j = 2; i = + - + - + -- j; printf("%d %d\n", i, j);
1 1
Show the output produced by the following program fragment.
int i = 1, j = 2;
int k = 3, m = 4;
i += j - (k *= m++);
printf(“%d %d %d %d\n”, i++, ++j, k–, –m);
-9 3 12 4
Show the output produced by the following program fragment.
int i = 1, j = 2, k = 3, m = 4;
i *= –j * (k *= –m);
printf(“%d %d %d %d\n”, i++, ++j, k–, –m);
9 2 9 2
Show the output produced by the following program fragment.
int i = 1, j = 2;
int k = 3, m = 4;
i %= j++ % (k += –m);
printf(“%d %d %d %d\n”, i++, ++j, k–, –m);
1 4 6 2
Show the output produced by the following program fragment.
int i = 1, j = 2;
int k = 3, m = 4;
i *= j / - (k -= ++m);
printf(“%d %d %d %d\n”, i++, ++j, k–, –m);
1 3 -2 4
If the value of n is 4 and m is 5, will the value of ++(n * m) be 21? Explain your answer.
++(n * m) = 21. The 4x5 will be evaluated first and then the ++ will be added after (the brackets has precedence).
In which order the following operators will be executed:
1. i j k
Will be executed from left to right*.
- The less than will be evaluated before the two logical or’s.
- The less than will be evaluated before the two logical and’s.
- Less than, and, or
- Less than, left to right.
- Left to right.
- less than, equal, and
- less than, not equal, or
Show the output produced by the following program fragment.
int i = 2, j = 3, k = i * j == 6;
printf(“%d\n”, k);
1
Show the output produced by the following program fragment.
int i = 5, j = 10, k = 1;
printf(“%d\n”, k > i < j);
1
Show the output produced by the following program fragment.
int i = 3, j = 2, k = 1;
printf(“%d\n”, i < j == j < k);
1
Show the output produced by the following program fragment.
int i = 3, j = 4, k = 5;
printf(“%d\n”, i % j + i < k);
0
Show the output produced by the following program fragment.
int i = 3, j = 4, k = 5;
printf(“%d\n”, i % j + i < k );
0
Show the output produced by the following program fragment.
int i = 3, j = 4, k = 5;
printf(“%d\n”, k = i * j == 6 );
0