- If originally x=4, y = 0, z = 2, what is the value of x, y, and z after the following code executes?
if ( x != 0 )
y = 3;
else
z = 2;
- If originally x=4, y = 0, z = 2, what is the value of x, y, and z after the following code executes?
if ( z == 2 )
y = 1;
else
x = 3;
- If originally x=4, y = 0, z = 2, what is the value of x, y, and z after the following code executes?
if ( x && y )
x = 3;
else
y = 2;
- If originally x=4, y = 0, z = 2, what is the value of x, y, and z after the following code executes?
if ( x || y || z )
y = 1;
else
z = 3;
- If originally x=4, y = 0, z = 2, what is the value of x, y, and z after the following code executes?
if ( x && y )
x = 3;
else
y = 2;
- If originally x=4, y = 0, z = 2, what is the value of x, y, and z after the following code executes?
if ( x )
if ( y )
z = 3;
else
z = 2;
- If originally x=0, y = 0, z = 1, what is the value of x, y, and z after the following code executes?
if ( z < x || y >= z && z == 1)
if ( z && y )
y = 1;
else
x = 1;
- If originally x=0, y = 0, z = 1, what is the value of x, y, and z after the following code executes?
if ( z = x < y )
{
y = 5;
z = -3;
}
else
x = 2;
- If originally x=0, y = 0, z = 1, what is the value of x, y, and z after the following code executes?
switch(x)
{
case 0 : x = 2;
y = 3;
case 1: x = 4;
default: y = 3;
x = 1;
}
- Rewrite the following code fragment using one switch statement
if ( ch == 'E' || ch == 'e' )
countE = 1;
else if ( ch == 'A' || ch == 'a' )
countA = 1;
else if ( ch == 'I' || ch == 'i' )
countI = 1;
else
printf ("Error - not A, E, or I\n");
countA = 1;
- Write the code that reads in a number for month and prints
out the month as a string (e.g. 1 = January, 2 = February, ...)
First implement as an if structure, then a switch
- True/False. You can implement any switch statement in to
an if-else structure.
- True/False. You can implement any if-else statement in to
a switch structure.
- What is the numeric value of the expression 3 < 4 ?
- Under what conditions will this code print ``water''?
if(T < 32)
printf("ice\n");
else if(T < 212)
printf("water\n");
else printf("steam\n");
- What would this code print?
int x = 3;
if(x)
printf("yes\n");
else printf("no\n");