NEW
Font size
WorksheetsC++ Programming Quiz (first)
Total questions: 52
Worksheet time: 26mins
What is the main difference between // and / */ comments?
// is for single-line comments, while /* */ is for multi-line comments
// is for multi-line comments, while /* */ is for single-line comments
Both can be used interchangeably
Neither is a valid comment syntax in C++
Which of the following is used to output text in C++?
cout <<
print()
console.log()
output()
What does the ++ operator do in C++?
Increases a variable's value by 1
Decreases a variable's value by 1
Multiplies a variable by 2
Divides a variable by 2
What is an algorithm?
A sequence of simple instructions that solve a problem
A random set of commands without structure
A method of compressing programming language syntax
A type of computer hardware
What is the purpose of the assignment operator (=) in C++?
It assigns a value to a variable
It compares two values
It swaps two variables
It multiplies two numbers
Which operator is used to check if one value is less than or equal to another in C++?
<=
<
>=
==
Which data type is used to store whole numbers without decimals in C++?
int
double
char
string
What is the purpose of a flowchart in algorithm design?
To visually represent the steps of an algorithm
To execute an algorithm
To write pseudocode
To debug a program
What is the correct syntax to declare an integer variable in C++?
int x;
variable x;
declare int x;
int = x;
Use ____________ to specify a block of code to be executed, if the same condition is false.
switch
break
continue
What was the main reason for the intentionally limited syntax of BASIC (1964)?
To make the language easy to learn
To improve execution speed
To support complex algorithms
To make it compatible with all operating systems
Use ____________ to specify many alternative blocks of code to be executed.
else
break
return
Which of the following is a multi-line comment in C++?
/* This is a comment */
// This is a comment
# This is a comment
-- This is a comment
Which operator is used to assign a value to a variable in C++?
=
==
!=
=>
How are syntax rules typically defined?
Using the Backus-Naur form
Through random trial and error
By copying rules from natural languages
Without any predefined structure
Which characteristic does a good algorithm have?
It is clear and unambiguous
It must be written in a programming language
It must be long and complex
It should have infinite steps
Which operator is used to check if two values are not equal in C++?
!=
==
<
>
What type of value does the condition inside an if statement evaluate to?
Boolean (true or false)
Integer only
String
Character
What is a programming language?
A set of keywords, symbols, identifiers, and rules for communication with a computer
A tool used only for web development
A type of hardware that runs computer programs
A collection of pre-written software applications
Which of the following is not a valid comment in C++?
! This is a comment !!
// This is a comment
/* This is a comment */
// Another comment
Which data type is used to store text in C++?
string
char
text
word
Which operator is used to check if two values are equal in C++?
==
=
!=
<=
How do you correctly start the main function in C++?
int main()
main++
main()
start main()
Which statement about the assignment operator is true?
It updates the value stored in a variable
It checks for equality between two variables
It swaps the values of two variables
It declares a variable without assigning a value
Which data type should be used to store a single character in C++?
char
string
character
text
What is the difference between = and == in C++?
= assigns a value, while == compares two values
= compares two values, while == assigns a value
Both perform assignment
Both perform comparison
Which operator is used to check if one value is greater than or equal to another in C++?
>=
>
<
==
What is the purpose of a compiler?
To translate source code into machine instructions
To directly execute source code without tr
Which operator is used to check if one value is greater than another in C++?
>
<
<=
!=
What is the purpose of a compiler?
To translate source code into machine instructions
To directly execute source code without translation
To convert machine instructions back to source code
To store software documentation
What happens to comments when a C++ program is compiled?
They are ignored by the compiler
They cause an error if too many are used
They slow down the execution of the program
They are included in the final executable file
What is the correct syntax for declaring a variable in C++?
type variableName = value;
variableName = value;
declare variableName = value;
type = variableName value;
What is the purpose of an if statement in C++?
To execute a block of code only if a specified condition is true
To execute a block of code in all cases
To declare a variable
To define a function
Why does source code need another program to execute?
Because computers can only execute their native machine instructions
Because source code is already in machine language
Because source code cannot be written by humans
Because source code does not contain executable instructions
Which keyword is used to display output in C++?
cout
cin
display
Use ____________ to specify a new condition to test, if the first condition is false.
else if
switch
break
while
Which of the following is NOT a component of programming language syntax?
Data compression methods
Keywords
Symbols
Identifiers
Use ____________ to specify a block of code to be executed, if a specified condition is true.
if
else
switch
loop
Which data type is used to store floating-point numbers with decimals in C++?
double
int
char
bool
Which of the following is a correct use of the assignment operator?
int x = 10;
int x == 10;
10 = x;
int x < 10;
Which of the following is a correct syntax for an if statement in C++?
if (x > 5) { cout << "x is greater than 5"; }
if x > 5 { cout << "x is greater than 5"; }
if (x > 5) cout << "x is greater than 5";
if x > 5 then { cout << "x is greater than 5"; }
What is the output of the following code snippet? if (10 < 5) { cout << "x is less than 5"; } cout << "End of program";
End of program
x is less than 5 End of program
x is less than 5
Compilation error
What is pseudocode?
A high-level representation of an algorithm
A type of programming language
A low-level machine code
A compiled version of an algorithm
What is the correct way to declare multiple variables of the same type in C++?
int a, b, c;
variable a, b, c;
variable int a, b, c;
declare int a, b, c;
What will happen if the condition inside an if statement is false?
The block of code inside {} will be skipped
The program will terminate
The condition will be ignored, and the block will execute
The compiler will throw an error
Which data type is used to store values with two states (true or false) in C++?
bool
int
char
string
What will be the value of x after the following statement? int x = 5; x = 10;
10
5
15
Undefined
What is the purpose of syntax in a programming language?
To define rules for structuring code
To improve execution speed
To make programming languages harder to learn
To store large amounts of data
What is a computer program?
A sequence or set of instructions in a programming language for a computer to execute
A hardware component of a computer
A physical storage device for programs
A mathematical formula used in software
What is the main goal of debugging in programming?
To find and fix errors in a program
To make the code run faster
To add more features to the program
To compile the program
What is the correct file extension for a C++ source file?
.cpp
.t
.k++
.kp
Which keyword is used to take user input in C++?
cin
cout
input
scanf
