0% found this document useful (0 votes)
11 views2 pages

Quiz

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
11 views2 pages

Quiz

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

Quiz

1. What are relational operators used for in C++?


A) Assigning values to variables
B) Comparing two values and returning a boolean result
C) Performing arithmetic calculations
D) Repeating loops

2. What does the switch statement in C++ allow you to do?


A) Compare two values
B) Execute one block of code from many options
C) Assign values to variables
D) Break out of loops immediately

3. Which of the following is NOT an arithmetic operator in C++?


A) +
B) -
C) %
D) &&

4. What happens if you don’t use a break statement in a switch case in C++?
A) The program will exit the switch block
B) The program will continue executing subsequent cases
C) An error will occur
D) None of the cases will execute

5. What is the role of the continue statement in loops?


A) It terminates the loop
B) It skips the remaining code in the current iteration and moves to the next iteration
C) It ends the program execution
D) It repeats the current iteration

6. In a for loop, what is the purpose of the initialization statement?


A) To define the condition to check at the end of the loop
B) To initialize the loop control variable
C) To perform the iteration
D) To terminate the loop

7. Which function from the <cmath> library returns the square root of a number in C++?
A) sqrt(x)
B) log(x)
C) ceil(x)
D) floor(x)
8. In a C++ program, how can you handle division by zero in a calculator using a switch
statement?
A) Use an if condition to check if the denominator is zero
B) Add a case to handle division by zero
C) Exit the program
D) Use an arithmetic operator to ignore division by zero

9. Which of the following is an example of a logical operator in C++?


A) ==
B) &&
C) +=
D) ++

10. What is the output of the following C++ code :

int a = 10, b = 20, c = 30;


int result = (a + b) * c / 2;

A) 450
B) 250
C) 300
D) 200

You might also like