WorksheetsIntroduction to C++ 2024/25
Total questions: 10
Worksheet time: 8mins
What is the correct syntax for an if statement in C++?
if x > 5 {}
if (x > 5) {}
if x > 5 then {}
if {x > 5}
Which of the following is a valid declaration of an integer variable in C++?
int 1 number;
number int;
int number;
number : int;
Which of the following is the correct way to read an integer from user input using cin?
cin >> int userInput;
int userInput;
cin << userInput;
int userInput;
cin >> userInput;
userInput = cin;
What data type would you use to store a single character in C++?
string
char
int
double
What will the following code display?
"x is greater than 5"
"x is not greater than 5"
"x is greater than 10"
None of the above
Which C++ logical operator is used for logical AND?
&&
||
!
&
What is the purpose of the "else if" statement in C++?
To declare variables
To create a nested if
To specify an alternative condition to be tested
To end a program
What is the correct way of checking if something is less than or equal to:
if(x>=10)
if(x=<10)
if(x<&&=10)
if(x<=10)
Which of the following correctly represents a floating-point variable?
float pi = 3.14;
float pi = "3.14";
int pi = 3.14;
float 3.14 = pi;
What will the following code print if y is set to 0?
if(y) { cout << "True"; }
else { cout << "False"; }
True
False
0
Nothing
