Professional Documents
Culture Documents
C++ Decision JJJJJ
C++ Decision JJJJJ
2. Which C++ logical expression correctly determines whether x and y are greater
than z?
a) (x && y > z )
b) (x > z ) && (y > z )
c) ( y > z ) && ( x > z )
d) all of the above
e) both b and c.
3. Evaluate the following C++ expression assuming i=5, j=10, k=15 and tell the
value (true/false).
i == k / j
4. Evaluate the following C++ expression assuming i=5 and k= 15 and tell the
value (true/false).
k%i<k/i
5. Evaluate the following C++ expression assuming x= true, y = false, z= true and
tell the value (true/false).
!z || (y || !x)
a) p && p
b) p || p
c) p && !p
d) p || !p
e) both b and d.
7. If the int variables i, j, and k contain the values 4, 5, and 20, respectively, and
flag is false, what is the value of the following logical expression?
!( i <= (j * k) || !flag )
a) 9
b) 20
c) 29
d) true
e) false
8. If the int variables i, j, and k contain the values 4, 5, and 20, respectively, what is
the value of the following logical expression:
( i + j != k && i * j > k )
a) 9
b) 20
c) 29
d) true
e) false
x=6
if (x>=6)
cout<< "Yes";
cout<<"No";
a) Yes
b) No
c) Yes
No
d) No output; no error
e) No output; compile-time error
Compiled by GDW Page 2
C++ Decision Statements Assignment
10. What is the output of the following code fragment assuming num is 10?
num = 10
if (num == 20)
cout<<"apple";
cout<<"orange";
a) apple
b) orange
c) apple
orange
d) No output; no error
e) No output; compile-time error
11. After execution of the following code, what will be the value of y?
x = 10
y = 20
if (x <= 10)
x = x + 10
y = y + 20
a) 10
b) 20
c) 30
d) 40
e) 50
12. After execution of the following code, what will be the value of x?
x = 10
if (x != 10)
x = 100
cout<<x;
a) 10
b) 20
c) 100
d) 110
e) Compile-time error