NEW
Font size
WorksheetsC++ Quiz
Total questions: 40
Worksheet time: 17mins
What is a correct syntax to output "Hello World" in C++?
System.out.println("Hello World");
Console.Writeline("Hello World");
cout<<"Hello World";
print("Hello World");
Which data type is used to create a variable that should store text?
Txt
String
string
myString
How do you create a variable with the numeric value 5?
int x=5;
num x=5
double x=5;
x=5;
How do you create a variable with the floating number 2.8?
int x = 2.8;
byte x = 2.8
double x = 2.8;
x = 2.8;
Which method can be used to find the length of a string?
getSize()
getLength()
length()
len()
Which operator is used to add together two values?
The + sign
The & sign
The * sign
Are the identifiers "firstname" and "FirstName" the same?
Yes
No
A C++ identifier can start with a digit.
True
False
What is the definition of an array?
An array is a mathematical equation used to calculate averages.
An array is a data structure that stores a collection of elements, each identified by at least one array index or key.
An array is a type of fish found in the ocean.
An array is a type of loop in programming languages.
How are arrays declared in C++?
By using parentheses instead of square brackets
By specifying the size first followed by the data type
By omitting the data type and size
By specifying the data type of the elements followed by square brackets containing the size of the array.
How are array indexes calculated in C++?
Array indexes in C++ start from 0.
Array indexes in C++ start from 1.
Array indexes in C++ start from -1.
Array indexes in C++ start from 100.
The semicolon (;) is used to?
Start a block of code
Terminate a function
Start a statement
End a statement
Which of the following is the input stream object?
>>
<<
cin
cout
Which of the following is NOT a VALID identifier?
X1
_X1
x1
_1x
1x
All variables must be declared before they are used.
True
False
.
What is the type of the temp variable?
var temp = 14.55;
Double
Boolean
Integer
String
What is the output of this program? Program int main() { cout<<"Hi everybody"; return 0; }
"Hi everybody"
Hi everybody"
Hi everybody
"Hi everybody
What is the only function all C++ programs must contain?
start()
system()
main()
program()
Which of the following is a valid relational operator in C++?
=<
=>
<=
=<>
Which of the following relational operators evaluates to true if the two compared expressions are not equal?
==
<=
!=
>
Which statement about the if-else structure is true?
The else block can exist without an if block.
An if block can execute multiple else blocks for a single condition.
The else block is executed only if the if condition evaluates to false.
The if condition can only test for equality.
Which of the following is the correct format of a "for" loop?
for(int i = 0; i < 10; i++);
for[int i = 0; i < 10; i++];
for(int i = 0; i < 10; i++)
for[int i = 0; i < 10; i++]
Which for loop will not work?
for (i=0; i<5; i++)
for (i=5; i<=10; i++)
for (i=5; i=10; i++)
for (i=5; i<100; i++)
The statement i++; is equivalent to ______.
i = i + i;
i = i + 1;
i = i - 1;
i--;
What output is produced by the following segment of code:
for(int i = 0; i < 10; i++)
cout << i << " ";
0 1 2 3 4 5 6 7 8 9 10
0 1 2 3 4 5 6 7 8 9
1 2 3 4 5 6 7 8 9 10
1 2 3 4 5 6 7 8 9
Infinite Loop
What output is produced by the following segment of code:
for (int x = 10; x > 0; x++)
cout << x << " ";
10 9 8 7 6 5 4 3 2 1
10 9 8 7 6 5 4 3 2 1 0
9 8 7 6 5 4 3 2 1
No Output
Infinite Loop
Make this code loop three times:
in tries= 0;
while(_________ ) {
cin>> “Looping!”;
tries++;
}
tries < 3
answer == 3
tries > 0
tries < 0
5<=5 evaluates to
true
false
Select the assignment operator
==
===
=
!=
The shape used to indicate a decision is to be made.
Circle
Diamond
Oval
Is it important for a programmer to plan the logic of his program?
Yes
No
It is used to compare two expressions and return true or false. The most common are > (greater than), < (less than), >= (greater than or equal to), <= (less than or equal to), == (equal to), != (not equal to).
Arithmetic Operator
Assignment Operator
Relational Operator
Logical Operator
results in "true" if the value is false, and vice versa. It effectively inverts the value. True becomes false and false becomes true. Overlaps with || but not with &&
Or (||)
Not (!)
And (&&)
Boolean
results in "true" only if two statements are both true; otherwise, the operator results in false. In coding, the two statements are called "operands"
And (&&)
Nor (!)
Or (||)
is Equal to (==)
int x=3, y=5;
bool result;
result = x > y;
The condition is?
TRUE
FALSE
int x=3, y=5;
bool result;
result = (x != y);
The condition is?
TRUE
FALSE
Suppose,
n = 5 m = 8
Then,
(n > 3) && (m > 5) evaluates to
TRUE
FALSE
Suppose,
n = 5 m = 8
Then,
!(n < 3) evaluates to
TRUE
FALSE
Which of the following is a correct way to write an if statement in C++?
if (x = 5) { ... }
if x = 5 { ... }
if (x == 5) { ... }
if x == 5 { ... }
What is the purpose of the else clause in an if statement?
To execute a block of code if the condition in the if statement is true
To execute a block of code if the condition in the if statement is false
To repeat a block of code a specific number of times
To exit a loop based on a certain condition
