Programming Quiz 4
What is assigned to the variable a given the statement below with the following assumptions: x=10, y=7, and z, a, and b are all int variables.
1
Given the following code segment, what is output after "result ="? int x=1, y=1, z=1; y=y+z; x=z+y; cout<<"result=" <<(x<y?y:x) <<endl;
3
Which line in the following program will cause a compiler error? #include<iostream> using namespace std; int main() { int number =5; if (number>=0&&<=100) cout<<"passed.\n"; else cout<<"failed.\n"; return 0; }
8
If you intend to place a block of statements within an if statement, you must place these around the block.
Curly braces{}
What will be the output of the following code segment after the user enters 0 at the keyboard? int x=-1; cout<<"Enter a 0 or a 1 from the keyboard: "; cin>>x; cout<<"true"<<endl; else cout<<"false"<<endl;
False
True/False: An expression that has any value other than 0 is considered true by an if statement.
True
True/False: As a rule of style, when writing an if statement you should indent the conditionally-executed statements.
True
True/False: If the sub-expression on the left side of the || operator is true, the expression on the right side will not be checked.
True
When an if statement is placed within the conditionally-executed code of another if statement, this is known as:
nesting
Which of the following expressions will determine whether x is less than or equal to y?
x<=y