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
Show the output produced by the following program fragment.
int i = 3, j = 4, k = 5;
printf(“%d\n”, i < j == k < i );
0
Show the output produced by the following program fragment.
int i = 3, j = 4, k = 5;
printf(“%d\n”, k > i < j );
1
Show the output produced by the following program fragment.
int i = 3, j = 4, k = 5;
printf(“%d\n”, i < j || ++ j < k );
printf(“%d %d %d\n”, i, j, k );
1
3 4 5
Show the output produced by the following program fragment.
int i = 7, j = 8, k = 9;
printf(“%d\n”, i – 7 && j ++ < k );
printf(“%d %d %d\n”, i, j, k );
Error. The i-7 is not legal. It is undefined.
Show the output produced by the following program fragment.
int i = 7, j = 8, k = 9;
printf(“%d\n”, ( i = j ) || ( j = k ));
printf(“%d %d %d\n”, i, j, k );
1
8 8 9
Show the output produced by the following program fragment.
int i = 1, j = 1, k = 1;
printf(“%d\n”, ++i || ++ j && ++ k );
printf(“%d %d %d\n”, i, j, k );
1
2 1 1
Show the output produced by the following program fragment. Assume that i, j, and k are int variables and you
compile the segment using C99. What will be the produced output if i, j, and k are bool?
i = 0; j = 1; k = 2;
printf(“%d %d %d\n”, i, j, k);
printf(“%d %d %d\n”, i–, j–, k–);
printf(“%d %d %d\n”, i, j, k);
int 0 1 2
0 1 2
-1 0 1
Bool i – not allowed for bool.
Show the output produced by the following program fragment. Assume that i, j, and k are int variables and you
compile the segment using C99. What will be the produced output if i, j, and k are bool?
i = 0; j = 1; k = 2;
printf(“%d %d %d\n”, i, j, k);
printf(“%d %d %d\n”, i++, j++, k++);
printf(“%d %d %d\n”, i, j, k);
int 0 1 2 bool 0 1 1
0 1 2 0 1 1
1 2 3 1 1 1
Show the output produced by the following program fragment. Assume that i, j, and k are int variables and you
compile the segment using C99. What will be the produced output if i, j, and k are bool?
i = 0; j = 1; k = 2;
printf(“%d %d %d\n”, i, j, k);
printf(“%d %d %d\n”, –i, –j, –k);
printf(“%d %d %d\n”, i, j, k);
int 0 1 2
-1 0 1
-1 0 1
Bool –i not allowed for bool.