C++ Practice Test Quiz!

Reviewed by Editorial Team
The ProProfs editorial team is comprised of experienced subject matter experts. They've collectively created over 10,000 quizzes and lessons, serving over 100 million users. Our team includes in-house content moderators and subject matter experts, as well as a global network of rigorously trained contributors. All adhere to our comprehensive editorial guidelines, ensuring the delivery of high-quality content.
Learn about Our Editorial Process
| By Mohzozo1900
M
Mohzozo1900
Community Contributor
Quizzes Created: 1 | Total Attempts: 3,154
| Attempts: 3,154 | Questions: 22
Please wait...
Question 1 / 22
0 %
0/100
Score 0/100
1. A C++ code line ends with? 

Explanation

In C++, a code line is terminated with a semicolon (;). This is a fundamental rule in the C++ programming language. The semicolon is used to indicate the end of a statement or expression. It is necessary to include a semicolon at the end of each line of code to ensure proper syntax and to separate different statements or expressions within the code.

Submit
Please wait...
About This Quiz
C++ Practice Test Quiz! - Quiz

This C++ Practice Test Quiz assesses fundamental programming skills in C++, covering basic operations, conditional statements, logical expressions, and compiler usage. It is designed for learners to test... see moretheir understanding and improve their problem-solving abilities in C++. see less

2. Which of the following is not a standard data type ? 

Explanation

The given options include three standard data types: int, char, and float. However, "data" is not a standard data type in most programming languages. It is a generic term that can refer to any type of information, but it is not a specific data type like int, char, or float. Therefore, "data" is the correct answer as it is not a standard data type.

Submit
3. The basic commands that a computer performs are ____, and performance of arithmetic and logical operations.

Explanation

The basic commands that a computer performs are input, output, and storage. Input refers to the process of receiving data or instructions from external sources, such as a keyboard or mouse. Output involves displaying or transmitting data or results to external devices, such as a monitor or printer. Storage refers to the ability of a computer to store and retrieve data and instructions for later use. These three commands are fundamental to the functioning of a computer system.

Submit
4. A program called a(n) ____ translates instructions written in high-level languages into machine code.

Explanation

A compiler is a program that takes instructions written in high-level languages and translates them into machine code. It analyzes the entire program, checking for errors and translating the code into a form that can be understood by the computer's processor. Unlike an assembler, which translates assembly language into machine code, a compiler works with higher-level languages like C, C++, or Java. A decoder is not responsible for translating high-level languages, and a linker is used to combine object files into an executable program. Therefore, a compiler is the correct answer for this question.

Submit
5. What is the output of the following code :  int main()  { int a=4 ;  (a>0)? cout<< " Number is positive " : cout<< " Number is negative " ; return 0 ;  }

Explanation

The output of the code will be "Number is positive". This is because the code uses the ternary operator "?:" to check if the value of variable "a" is greater than 0. If it is true, it will print "Number is positive", otherwise it will print "Number is negative". In this case, since the value of "a" is 4 which is greater than 0, the condition is true and "Number is positive" will be printed.

Submit
6. What is the output of the following C++ code? int x = 35; int y = 45; int z; if (x > y) z = x + y; else z = y – x; cout << x << " " << y << " " << z << endl;

Explanation

The code initializes variables x and y with the values 35 and 45 respectively. It then checks if x is greater than y. Since 35 is not greater than 45, the else block is executed. In the else block, z is assigned the value of y minus x, which is 45 - 35 = 10. Finally, the values of x, y, and z are printed, resulting in the output "35 45 10".

Submit
7. Which of the following is not a relational operator in the C++ program? 

Explanation

The equal sign (=) is not a relational operator in C++. It is actually an assignment operator used to assign a value to a variable. Relational operators are used to compare values and return a boolean result, such as whether one value is equal to another (==) or greater than or equal to another (>=).

Submit
8. Suppose that x, y, z, and w are int variables, and x = 3, y = 4, z = 7, and w = 1; What is the output of the following statement?    cout << " x == y : " << (x == y ) << endl;

Explanation

The output of the statement is "x == y: 0". This is because the expression (x == y) evaluates to false, since the value of x (3) is not equal to the value of y (4). In C++, when a comparison is true, it is represented as 1, and when it is false, it is represented as 0. Therefore, the output is 0.

Submit
9. Suppose that x, y, z, and w are int variables, and x = 3, y = 4, z = 7, and w = 1; What is the output of the following statement?    cout << " ! (z > w ) : " << ! (z > w ) << endl;

Explanation

The output of the statement is " ! (z > w) : 0". This is because the expression "(z > w)" evaluates to true (1) since 7 is greater than 1. The "!" operator negates the result, so it becomes false (0). The statement then outputs the string " ! (z > w) : " followed by the result of the expression, which is 0.

Submit
10. Which of the following is a unary operator? 

Explanation

The correct answer is ++. A unary operator is an operator that operates on a single operand. In this case, the ++ operator is a unary operator because it increments the value of the operand by 1.

Submit
11. Which of the following is illegal identifier ?  

Explanation

The identifier "return" is illegal because it is a reserved keyword in many programming languages, including C++, Java, and Python. Reserved keywords are predefined and have special meanings in the language, so they cannot be used as identifiers for variables, functions, or other entities in the program.

Submit
12. C++ program may have more than one main function? 

Explanation

A C++ program cannot have more than one main function. The main function is the entry point of the program, and there can only be one entry point. Having multiple main functions would lead to ambiguity and confusion in the program's execution. Therefore, it is false that a C++ program may have more than one main function.

Submit
13. The driver function of a C++ program that if it is not present in a program, no execution can take place: 

Explanation

The driver function of a C++ program is the main function. It is the entry point of the program where the execution starts. Without the main function, the program cannot be executed as there would be no starting point for the program to begin execution. Therefore, if the main function is not present in a C++ program, no execution can take place.

Submit
14. The output of the following code is :  int main()  { int n=17 ; cout << ( n == 16 ) << endl ;  return 0 ;  }  

Explanation

The code is checking if the value of n is equal to 16. Since n is initialized as 17, the condition (n == 16) evaluates to false. The false value is then printed to the console using the cout statement. In C++, false is represented as 0. Therefore, the output of the code is 0.

Submit
15. Which of the following expressions correctly determines that x is greater than 10 and less than 20?

Explanation

The expression "10

Submit
16. What is the output of the following code:  int main()  { int a=98 ; double b=5 ; cout << a/3.0 ;  return 0 ;  }

Explanation



In the expression a/3.0, the value of a is an integer (98) and the value of 3.0 is a double. When performing arithmetic operations with operands of different types, C++ promotes the operands to the highest data type involved in the operation, which in this case is double. Therefore, the division operation will be performed using double arithmetic, resulting in the decimal value 32.6667.
Submit
17. The output of the following code is :  int main()  { float x=1 ;  cout << ( x == 3.0 / 7.0 + 2.0 / 7.0 + 2.0 / 7.0 ) ;  return 0 ;  }

Explanation

The output of the code will be "false" or "0". This is because the expression (3.0 / 7.0 + 2.0 / 7.0 + 2.0 / 7.0) evaluates to a value slightly less than 1.0 due to the limitations of floating-point precision. When comparing this value to the float variable x, which is initialized to 1.0, the result is false. Therefore, the correct answer is "none of above".

Submit
18. What is the output of the following code:  int main()  {  int x=7 ;  if ( x=8)   cout << x-1 ;  else  cout << x+1 ;  return 0 ;  }

Explanation

The output of the code is 7. In the if statement, the condition x=8 is used instead of x==8. This is an assignment operator, not a comparison operator. As a result, the value of x is set to 8. Since the condition is true, the code inside the if statement is executed, which is cout << x-1. Therefore, the output is 7.

Submit
19. Suppose that x is an int variable. Which of the following expressions always evaluates to true?

Explanation

The expression (x > 0) || (x <= 0) will always evaluate to true for any integer x. This is because the logical OR (||) operator ensures that if at least one of the conditions is true, the entire expression is true. Since any integer x will either be greater than 0 or less than or equal to 0, this condition covers all possible integer values.

The other expressions have conditions that can never be true simultaneously (such as x > 0 and x <= 0 both being true at the same time), so they do not always evaluate to true.

Submit
20. What is the output of the following code :  int main() { int num = 9;  if (num<0);  num= -num ;  return o ;  }

Explanation



The key points to note are:

The if (num < 0); line has a semicolon at the end, which terminates the if statement. This means that the subsequent line num = -num; will execute regardless of the if condition.

As a result, num will be assigned the value -num, making num negative.

However, there is a mistake in the return statement: return o; should be return 0;. Assuming this is a typographical error and should be corrected to return 0;, the program will compile and run, but since there are no cout statements to display output, the program's output will not show any value in a typical run.
Submit
21. The type of error in the following statement is : int a=b/0     //  b is defined as int 

Explanation

The given statement will result in a run-time error because it is trying to divide a number by zero. In programming, dividing by zero is not allowed and will cause an error during the execution of the program.

Submit
22. What is the output of the following code:  int main ()  { int x=2 , y ;  //x=x*2 ;  y=x++ ;  cout << "x= " << x << "\ty="  << y ;  return 0 ;  }

Explanation

The code starts by initializing the variable x to 2. Then, the line "y = x++" assigns the value of x to y and then increments the value of x by 1. After that, the code prints the values of x and y using the "cout" statement. Since x was incremented by 1 before printing, its value is 3. The value of y remains 2 because it was assigned the value of x before it was incremented. Therefore, the output of the code is "x = 3 y = 2".

Submit
View My Results

Quiz Review Timeline (Updated): Jan 19, 2025 +

Our quizzes are rigorously reviewed, monitored and continuously updated by our expert board to maintain accuracy, relevance, and timeliness.

  • Current Version
  • Jan 19, 2025
    Quiz Edited by
    ProProfs Editorial Team
  • Oct 24, 2017
    Quiz Created by
    Mohzozo1900
Cancel
  • All
    All (22)
  • Unanswered
    Unanswered ()
  • Answered
    Answered ()
A C++ code line ends with? 
Which of the following is not a standard data type ? 
The basic commands that a computer performs are ____, and performance...
A program called a(n) ____ translates instructions written in...
What is the output of the following code :  ...
What is the output of the following C++ code?...
Which of the following is not a relational operator in the C++...
Suppose that x, y, z, and w are int variables, and x = 3, y = 4, z =...
Suppose that x, y, z, and w are int variables, and x = 3, y = 4, z =...
Which of the following is a unary operator? 
Which of the following is illegal identifier ?  
C++ program may have more than one main function? 
The driver function of a C++ program that if it is not present in a...
The output of the following code is :  ...
Which of the following expressions correctly determines that x is...
What is the output of the following code:  ...
The output of the following code is :  int main()  { float...
What is the output of the following code:  ...
Suppose that x is an int variable. Which of the following expressions...
What is the output of the following code :  ...
The type of error in the following statement is : ...
What is the output of the following code:  ...
Alert!

Advertisement