Font size
WorksheetsAlgorithm and Programming Concepts Quiz
Total questions: 64
Worksheet time: 37mins
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
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 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 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 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
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
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 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
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
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
Which of the following is NOT a component of programming language syntax?
Data compression methods
Keywords
Symbols
Identifiers
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
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
Which of the following is a correct variable declaration in C++?
int num;
variable num;
declare num;
num int;
Which data type should be used to store a single character in C++?
char
string
character
text
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;
Which operator is used to assign a value to a variable in C++?
=
==
:=
=>
What is the correct syntax to declare an integer variable in C++?
int x;
variable x;
declare int x;
int = x;
Which of the following is used to output text in C++?
cout <<
print()
console.log()
output()
What is the correct file extension
Which of the following is used to output text in C++?
cout <<
print()
console.log()
output()
What is the correct file extension for a C++ source file?
.cpp
.t
.k++
.kp
How do you correctly start the main function in C++?
int main()
main++
main()
start main()
Which data type is used to store a single character in C++?
char
string
character
text
Which data type is used to store whole numbers without decimals in C++?
int
double
char
string
Which data type is used to store floating-point numbers with decimals in C++?
double
int
char
bool
Which data type is used to store text in C++?
string
char
text
word
Which data type is used to store values with two states (true or false) in C++?
bool
int
char
string
What is the correct syntax for declaring a variable in C++?
type variableName = value;
variableName = value;
declare variableName = value;
type = variableName value;
Which keyword is used to take user input in C++?
cin
cout
input
scanf
Which keyword is used to display output in C++?
cout
cin
display
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 of the following is a correct use of the assignment operator?
int x = 10;
int x == 10;
10 = x;
int x < 10;
What will be the value of x after the following statement? int x = 5; x = 10;
10
5
15
Undefined
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
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
What is the purpose of comments in C++?
To add explanations or notes in the code that are ignored by the compiler
To execute additional lines of code
To speed up program execution
To store variable values
Which of the following is a single-line comment in C++?
// This is a comment
/* This is a comment */
# This is a comment
-- This is a comment
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
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 way to comment out multiple lines in C++?
/* This is a multi-line comment */
// This is a multi-line comment //
# This is a multi-line comment #
-- This is a multi-line comment --
Which of the following statements about comments is true?
Comments improve code readability but do not affect execution
Comments are required for the program to run correctly
Comments execute before the main function
Comments can store variable values
What is the main difference between // and /* ... */ comments?
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 not a valid comment in C++?
!! This is a comment !!
// This is a comment
/* This is a comment */
// Another comment
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
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 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 type of value does the condition inside an if statement evaluate to?
Boolean (true or false)
Integer only
String
Character
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
Use ________ to specify a block of code to be executed, if a specified condition is true
if
else
switch
loop
Use ________ to specify a block of code to be executed, if the same condition is false
else
switch
break
continue
Use ________ to specify a new condition to test, if the first condition is false
else if
switch
break
while
Use ________ to specify many alternative blocks of code to be executed
switch
else
break
return
Which operator is used to check if one value is less than another in C++?
<
<=
>
>=
Which operator is used to check if one value is less than or equal to another in C++?
<=
<
>=
==
Which operator is used to check if one value is greater than another in C++?
>
<
<=
!=
Which operator is used to check if one value is greater than or equal to another in C++?
>=
>
<
==
Which operator is used to check if two values are equal in C++?
==
=
!=
<=
Which operator is used to check if two values are not equal in C++?
!=
==
<
>
Which operator is used to increase a variable's value by 1 in C++?
++
--
+=
-=
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
Which operator is used to decrease a variable's value by 1 in C++?
--
++
-=
+=
What does the -- operator do in C++?
Decreases a variable's value by 1
Increases a variable's value by 1
Multiplies a variable by 2
Divides a variable by 2
