Next: Exercises Up: The if statement Previous: Summary

Multiple Choice Questions

if statements


Try to answer as many of the following Multi-choice questions as you can.

Do not panic if you make any errors. You can always start again by clicking on the "Restart" button, located at the bottom.


Your Details


Please enter your full name :


The Questions


Q1.

If y has the value 5 what will be the value of the variable y after the following piece of C++ is executed?

if (y > 0)
    y += 2;
 
5
7
2

Q2.

If p has the value 3 and max has the value 5, what will be the value of the variable max after the following piece of C++ is executed?

if (p < max)
    max = p;
 
5
3

Q3.

If x has the value 5.0 what will be the value of the variable countneg after the following piece of C++ is executed?

countneg = 0;
if (x < 0.0)
    negsum = negsum + x;
    countneg = countneg + 1;
 
0
1
5

Q4.

If this is changed as follows what would be the value of countneg after execution of the code?

countneg = 0;
if (x < 0.0)
   {
    negsum = negsum + x;
    countneg = countneg + 1;
   }
 
0
1
5


Once you have completed all the questions, and are quite happy with your answers. Then click on the "Submit Answers" button.

Clicking the "Restart" button will clear all your answers, ready to re-enter them.


Please send any comments about this page 



Next: Exercises Up: The if statement Previous: Summary