The editorial team at ProProfs Quizzes consists of a select group of subject experts, trivia writers, and quiz masters who have authored over 10,000 quizzes taken by more than 100 million users. This team includes our inhouse seasoned quiz moderators and subject matter experts. Our editorial experts, spread across the world, are rigorously trained using our comprehensive guidelines to ensure that you receive the highest quality quizzes.
A compilation of previous test questions and their answers.
Questions and Answers
1.
Which of the following is a C++ keyword?
A.
Number
B.
Integer
C.
Main
D.
Double
E.
Single
Correct Answer
D. Double
Explanation The keyword "double" is a valid C++ keyword. In C++, "double" is used to declare a variable that can hold floatingpoint numbers with double precision. It is a data type that can store decimal numbers with a larger range and more precision compared to the "float" data type.
Rate this question:
2.
Which of the following about C++ identifiers is false?
A.
'Sales' and 'sales' are considered different identifiers
B.
An identifier cannot start with a digit
C.
'the average' is a valid identifier
D.
A keyword cannot be used as an identifier
E.
An identifier must be declared by the programmer or in an #included library
Correct Answer
C. 'the average' is a valid identifier
Explanation In C++, identifiers are casesensitive, which means 'Sales' and 'sales' are considered different identifiers. An identifier cannot start with a digit, so the statement is true. 'the average' is not a valid identifier because it contains a space, and spaces are not allowed in identifiers. Keywords in C++ cannot be used as identifiers, so the statement is true. An identifier must be declared by the programmer or in an #included library, so the statement is true. Therefore, the false statement is that 'the average' is a valid identifier.
Rate this question:
3.
If you want to have a variable which can hold a number with a fractional part (such as 8.67) you should declare it to be of what type?
A.
Char
B.
Double
C.
Int
D.
String
E.
Bool
Correct Answer
B. Double
Explanation If you want to have a variable that can hold a number with a fractional part, such as 8.67, you should declare it to be of the double type. The double data type in programming is used to store decimal numbers with a higher precision than the float data type. It can hold both whole numbers and numbers with decimal places, making it suitable for storing numbers with fractional parts.
Rate this question:
4.
In C++, a (single line) comment begins with?
A.
\ \
B.
/ /
C.
!
D.
*
E.
(*
Correct Answer
B. / /
Explanation In C++, a single line comment begins with two forward slashes "//". This allows the programmer to insert comments in the code for better understanding or to provide explanations. Anything written after the "//" is ignored by the compiler and is not executed as code. This is a common practice in programming languages to add comments that can help other developers or even the same developer in the future to understand the code more easily.
Rate this question:
5.
To display the message Welcome ! the following can be used in C++
A.
Cout
B.
Cout >> "Welcome !" ;
C.
Cin
D.
Cout
E.
Cin >> Welcome ! ;
Correct Answer
A. Cout
Explanation The correct answer is cout. In C++, cout is used to display output to the console. It is followed by the insertion operator '
Rate this question:
6.
Which of the following will produce the output Hello World ?
A.
Cout
B.
Cout
C.
Cout
D.
Cout
E.
Cout
Correct Answer
E. Cout
Explanation The correct answer is "cout" because "cout" is the standard output stream in C++ and is used to display output on the console. In this case, "cout" is being used to display the string "Hello World".
Rate this question:
7.
Which of the following is NOT a valid assignment statement?
A.
X = 15;
B.
X = y;
C.
15 = y;
D.
Y = x;
E.
Y = 15;
Correct Answer
C. 15 = y;
Explanation In an assignment statement, the value on the right side is assigned to the variable on the left side. However, in the statement "15 = y;", a constant value (15) is being assigned to a variable (y), which is not a valid assignment. The correct syntax for an assignment statement is variable = value.
Rate this question:
8.
Which arithmetic operator will be performed first in calculating the value of a + b * c  d / e % f ?
A.
+
B.

C.
*
D.
/
E.
%
Correct Answer
C. *
Explanation In the given expression, the arithmetic operator that will be performed first is the multiplication operator (*). This is because multiplication has a higher precedence than addition, subtraction, division, and modulo. Therefore, the multiplication of b and c will be performed first, followed by the addition of a, subtraction of the result with d, division of the new result by e, and finally, taking the modulo of the final result with f.
Rate this question:
9.
Which arithmetic operator will be performed last in calculating the value ofa + b * c  d / e % f ?
A.
+
B.

C.
*
D.
/
E.
%
Correct Answer
B. 
Explanation The arithmetic operator that will be performed last in calculating the value of a + b * c  d / e % f is the subtraction operator (). This is because in the order of operations, multiplication and division are performed before addition and subtraction. Additionally, the modulus operator (%) is performed before division. Therefore, the subtraction operator () will be performed last.
Rate this question:
10.
The arithmetic expression a+b is written C++ as? c+d
A.
(a+b) / c+d
B.
A+b / c+d
C.
A + (b/c) +d
D.
A+b/(c+d)
E.
(a+b) / (c+d)
Correct Answer
E. (a+b) / (c+d)
Explanation The correct answer is (a+b) / (c+d) because it correctly represents the arithmetic expression a+b in C++. In C++, the division operator (/) is used to perform division, and the parentheses are used to group expressions and control the order of operations. Therefore, to divide the sum of a and b by the sum of c and d, we need to enclose a+b and c+d in parentheses.
Rate this question:
11.
For the expression x%y to be valid, data types of x and y should be (respectively)?
A.
Float and double
B.
Int and int
C.
Double and int
D.
Char and float
E.
Float and bool
Correct Answer
B. Int and int
Explanation The expression x%y is the modulus operator in many programming languages, which gives the remainder when x is divided by y. In order for this expression to be valid, both x and y should be of integer data type. The modulus operator is not defined for float, double, char, or bool data types.
Rate this question:
12.
Which pair of operators has the same precedence?
A.
+ and *
B.
 and /
C.
+ and /
D.
+ and 
E.
 and *
Correct Answer
D. + and 
Explanation The pair of operators + and  have the same precedence. This means that when evaluating an expression, both + and  will be evaluated from left to right in the order they appear. For example, in the expression 5 + 3  2, the addition operation (+) will be performed first, followed by the subtraction operation ().
Rate this question:
13.
Which of the following is not a relational operator in C++?
A.
B.
C.
>
D.
>=
E.
=
Correct Answer
E. =
Explanation The given answer is correct because the "=" operator is not a relational operator in C++. It is actually the assignment operator, used to assign a value to a variable. Relational operators in C++ are used to compare two values and return a boolean result, such as ">", "=", "
Rate this question:
14.
Which expression has the value true when someone's income is at least 15000 but less than 50000; and has the value false otherwise?
A.
15000
B.
(15000
C.
(15000 > income) && (income < 50000)
D.
(15000 50000)
E.
(15000 > income)  (income < 50000)
Correct Answer
B. (15000
Explanation The expression (15000 < income) && (income < 50000) has the value true when someone's income is at least 15000 but less than 50000, and false otherwise.
Rate this question:
15.
What is the output from the following program fragment?if ((2 + 2) == 4) cout << "Ha Ha\n" ;else cout << "Hee Hee\n" ;
A.
Ha Ha
B.
Hee Hee
C.
'Ha Ha' on one line followed by 'Hee Hee' on the next line
D.
No output because there is a syntax error
E.
No output, but there is no syntax error
Correct Answer
A. Ha Ha
Explanation The output from the program fragment is "Ha Ha". This is because the condition `(2 + 2) == 4` evaluates to true, so the code inside the if statement executes and prints "Ha Ha" to the console. The else statement is not executed in this case.
Rate this question:
16.
For which values of number will this program display Hello on the output screen?if ((number % 2) == 0) cout << "Hello" ;
A.
For any value in number
B.
For no value
C.
For positive numbers
D.
For even values
E.
For negative values
Correct Answer
D. For even values
Explanation The program will display "Hello" on the output screen for even values of the number. This is because the condition in the if statement checks if the number is divisible by 2 (i.e., if the remainder of the division is 0). If the condition is true, the program will execute the statement inside the if block, which is to output "Hello". Therefore, only when the number is an even value, the program will display "Hello" on the output screen.
Rate this question:
17.
What is the output from the following program fragment?int k(4) , sum ;while (k >= 1) { sum = 0 ; sum = sum + k ; k = k  1 ;} // end whilecout << sum << endl ;
A.
1
B.
2
C.
3
D.
4
E.
None of these
Correct Answer
A. 1
Explanation The output of the program fragment will be 1. This is because the program initializes the variable "sum" to 0 and then enters a while loop that will execute as long as "k" is greater than or equal to 1. Within the loop, the value of "k" is added to "sum" and then "k" is decremented by 1. Since the loop runs only once with "k" initially set to 4, the value of "sum" will be 4 after the loop. However, since "sum" is declared within the loop, it is a local variable and will not retain its value outside of the loop. Therefore, when the value of "sum" is printed outside the loop, it will be 1, which is the initial value of "sum" before the loop execution.
Rate this question:
18.
What is the output from the following program fragment?z = 15 ;while (z < 20) z = z + 2 ;cout << z << endl ;
A.
15
B.
17
C.
19
D.
20
E.
21
Correct Answer
E. 21
Explanation The program initializes the variable z to 15. It then enters a while loop that continues as long as z is less than 20. Inside the loop, z is incremented by 2. The loop continues until z becomes 21, which is the first value greater than or equal to 20. Therefore, the output of the program is 21.
Rate this question:
19.
If x and y are integer variables, and we want to calculate the result of dividing x by y using real (floating point) division, we should use the expression?
A.
X / y
B.
Static_cast(x / y)
C.
Static_cast(x) / y
D.
1.0 * (x / y)
E.
(x / y) * 1.0
Correct Answer
C. Static_cast(x) / y
Explanation To calculate the result of dividing x by y using real division, we need to ensure that at least one of the variables is casted to a floatingpoint type. The expression "static_cast(x) / y" casts x to a floatingpoint type, allowing for real division to occur between x and y. This ensures that the result will be a floatingpoint value, rather than an integer value that would be obtained from integer division.
Rate this question:
20.
To generate a random integer value between 1 and 6 (both inclusive), we can use the expression:
A.
1 + rand() / 6
B.
6 + rand() / 1
C.
6 + rand() % 1
D.
1 + rand() % 6
E.
(1 + rand()) / 6
Correct Answer
D. 1 + rand() % 6
Explanation The expression "1 + rand() % 6" generates a random integer value between 1 and 6 (both inclusive). The "rand()" function generates a random number, and the "% 6" part of the expression ensures that the result is within the range of 0 to 5. Adding 1 to the result shifts the range to 1 to 6.
Rate this question:
21.
Consider the following C++ fragmentif (average == 100) ; cout << "Congratulations!\n" ;Which of the following is NOT true?
A.
The message 'Congratulations' is displayed regardless of the value in the variable 'average'
B.
There is an empty (null) statement in this fragment
C.
This fragment contains a syntax error so the program will not run
D.
The if does not control the cout statement
E.
The output from the fragment will not change if the == is replaced by !=
Correct Answer
C. This fragment contains a syntax error so the program will not run
Explanation The given statement is incorrect because there is no syntax error in the given C++ fragment. The if statement controls whether the cout statement will be executed or not based on the condition average == 100. If the condition is true, then the message "Congratulations!" will be displayed. If the condition is false, then the cout statement will not be executed. Therefore, the correct answer is that the output from the fragment will not change if the == is replaced by !=.
Rate this question:
22.
Which of the following is true about the Boolean expression (ch != 'Y')  (ch != 'N') Assuming that ch is of type char?
A.
The expression has the value true regardless if the value in ch
B.
The expression has the value false regardless of the value in ch
C.
The value of the expression cannot be determined unless we know the value in ch
D.
The expression has a syntax error
E.
The expression is valid, but it is NOT a Boolean expression
Correct Answer
A. The expression has the value true regardless if the value in ch
Explanation The given Boolean expression (ch != 'Y')  (ch != 'N') will always evaluate to true regardless of the value in ch. This is because if ch is equal to 'Y', then the first condition (ch != 'Y') will be false, but the second condition (ch != 'N') will be true. Similarly, if ch is equal to 'N', then the first condition will be true and the second condition will be false. In any other case, both conditions will be true. Therefore, the overall expression will always be true.
Rate this question:
23.
If the variables test1, test2, test3 are all of int type, then which of the following expressions will calculate the average of their values correctly (it may have a fractional part)?
A.
Test1 + test2 + test3 / 3
B.
(test1 + test2 + test3) / 3
C.
Test1 + test2 + test3 / 3.0
D.
Test1 + test2 + (test3 / 3.0)
E.
None of the above
Correct Answer
E. None of the above
Explanation The correct answer is "none of the above" because in all the given options, the division operation is performed before the addition operation. To calculate the average correctly, the addition operation should be performed first, and then the division operation should be applied to the sum.
Rate this question:
24.
Which of the following is a true statement?
A.
A variable declared in the main function has a definite value just by being declared (as in int x ;)
B.
A variable can be given an initial value when declared, but it need not be done
C.
A variable must be given an initial value when declared (as in int x(5) ;
D.
All of the above
E.
None of the above
Correct Answer
B. A variable can be given an initial value when declared, but it need not be done
Explanation When a variable is declared in the main function, it does not have a definite value just by being declared. However, it can be given an initial value when declared using the syntax int x = 5; but it is not mandatory to do so. Therefore, the statement "A variable can be given an initial value when declared, but it need not be done" is true.
Rate this question:
25.
Which of the following statements has an output that cannot be predicted?
A.
Cout
B.
Cout
C.
Cout
D.
All of the above
E.
None of the above
Correct Answer
D. All of the above
Explanation The statement "all of the above" is the correct answer because the output of the "cout" statement cannot be predicted. The "cout" statement is used for outputting data to the console, but without any specific data or variables being provided, it is impossible to determine what the output will be. Therefore, all three "cout" statements mentioned in the options can have unpredictable outputs.
Rate this question:
26.
What is the letter grade computed by this fragment when 95 is entered?int grade ;char Letter ;cout << "Enter grade: " ; cin >> grade ;if (grade >= 70) Letter = 'C' ;else if (grade >= 90) Letter = 'A' ;else if (grade >= 80) Letter = 'B' ;else if (grade >= 60) Letter = 'D' ;else Letter = 'F' ;
A.
A
B.
B
C.
C
D.
D
E.
F
Correct Answer
C. C
Explanation The given code fragment assigns a letter grade based on the value of the variable "grade". The code checks the value of "grade" against different conditions using ifelse statements. If "grade" is greater than or equal to 70, it assigns the letter 'C' to the variable "Letter". Since 95 is greater than 70, the condition is true and the code assigns 'C' to "Letter". Therefore, the letter grade computed when 95 is entered is 'C'.
Rate this question:
27.
What is the letter grade computed by this fragment when 87 is entered?int grade ;char Letter ;cout << "Enter grade: " ; cin >> grade ;if (grade >= 70) Letter = 'C' ;else if (grade >= 90) Letter = 'A' ;else if (grade >= 80) Letter = 'B' ;else if (grade >= 60) Letter = 'D' ;else Letter = 'F' ;
A.
A
B.
B
C.
C
D.
D
E.
F
Correct Answer
C. C
Explanation The correct answer is C because the given code fragment uses a series of ifelse statements to assign a letter grade based on the entered grade. The code checks the entered grade against different ranges (70 and above for C, 90 and above for A, 80 and above for B, 60 and above for D) and assigns the corresponding letter grade to the variable "Letter". If none of the conditions are met, the code assigns 'F' to "Letter". Therefore, when 87 is entered, it falls into the range of 70 and above, so the letter grade computed is C.
Rate this question:
28.
What is the letter grade computed by this fragment when 73 is entered?int grade ;char Letter ;cout << "Enter grade: " ; cin >> grade ;if (grade >= 70) Letter = 'C' ;else if (grade >= 90) Letter = 'A' ;else if (grade >= 80) Letter = 'B' ;else if (grade >= 60) Letter = 'D' ;else Letter = 'F' ;
A.
A
B.
B
C.
C
D.
D
E.
F
Correct Answer
C. C
Explanation The correct answer is C.
In this code fragment, the input grade is compared to different values to determine the corresponding letter grade. The first condition checks if the grade is greater than or equal to 70, which is true for 73. Therefore, the letter grade assigned to the variable Letter is 'C'.
Rate this question:
29.
What is the letter grade computed by this fragment when 66 is entered?int grade ;char Letter ;cout << "Enter grade: " ; cin >> grade ;if (grade >= 70) Letter = 'C' ;else if (grade >= 90) Letter = 'A' ;else if (grade >= 80) Letter = 'B' ;else if (grade >= 60) Letter = 'D' ;else Letter = 'F' ;
A.
A
B.
B
C.
C
D.
D
E.
F
Correct Answer
D. D
Explanation The letter grade computed by this fragment when 66 is entered is 'D'. This is because the code uses a series of ifelse statements to determine the letter grade based on the inputted grade. Since 66 is greater than or equal to 60, but less than 70, it falls into the condition where Letter is assigned the value 'D'.
Rate this question:
30.
What is the letter grade computed by this fragment when 45 is entered?int grade ;char Letter ;cout << "Enter grade: " ; cin >> grade ;if (grade >= 70) Letter = 'C' ;else if (grade >= 90) Letter = 'A' ;else if (grade >= 80) Letter = 'B' ;else if (grade >= 60) Letter = 'D' ;else Letter = 'F' ;
A.
A
B.
B
C.
C
D.
D
E.
F
Correct Answer
E. F
Explanation The letter grade computed by this fragment when 45 is entered is 'F'. This is because the code first checks if the grade is greater than or equal to 70, which it is not. Then it checks if the grade is greater than or equal to 90, which it is not. It continues checking the other conditions and since none of them are true, the final else statement assigns the value 'F' to the variable Letter.
Rate this question:
31.
Determine the final value of the int variable angle when 0 is input.cout << "Enter angle: " ; cin >> angle ;if (angle >= 5) angle = angle + 5 ;else if (angle > 2) angle = angle + 10 ;else if (angle <= 0) angle = angle  15 ;else angle = angle +100 ;
Correct Answer 15
Explanation The given code snippet is checking the value of the variable "angle" using multiple ifelse statements. If the value of "angle" is greater than or equal to 5, it adds 5 to the variable. If the value of "angle" is greater than 2 but less than 5, it adds 10 to the variable. If the value of "angle" is less than or equal to 0, it subtracts 15 from the variable. In this case, the input value is 0 which satisfies the condition "angle
Rate this question:
32.
Determine the final value of the int variable angle when 5 is input.cout << "Enter angle: " ; cin >> angle ;if (angle >= 5) angle = angle + 5 ;else if (angle > 2) angle = angle + 10 ;else if (angle <= 0) angle = angle  15 ;else angle = angle +100 ;
Correct Answer 10
Explanation The final value of the int variable angle will be 10. This is because the input value of 5 satisfies the condition in the first if statement (angle >= 5), so the value of angle is increased by 5. Since none of the other conditions are met, the value remains unchanged.
Rate this question:
33.
Determine the final value of the int variable angle when 1 is input.cout << "Enter angle: " ; cin >> angle ;if (angle >= 5) angle = angle + 5 ;else if (angle > 2) angle = angle + 10 ;else if (angle <= 0) angle = angle  15 ;else angle = angle +100 ;
Correct Answer 101
Explanation The final value of the int variable angle is 101. This is because the input value of 1 satisfies the condition of the last "else" statement, which adds 100 to the angle. Therefore, the value of angle is 1 + 100 = 101.
Rate this question:
34.
Determine the final value of the int variable angle when 15 is input.cout << "Enter angle: " ; cin >> angle ;if (angle >= 5) angle = angle + 5 ;else if (angle > 2) angle = angle + 10 ;else if (angle <= 0) angle = angle  15 ;else angle = angle +100 ;
Correct Answer 20
35.
Determine the final value of the int variable angle when 5 is input.cout << "Enter angle: " ; cin >> angle ;if (angle >= 5) angle = angle + 5 ;else if (angle > 2) angle = angle + 10 ;else if (angle <= 0) angle = angle  15 ;else angle = angle +100 ;
Correct Answer 20
Explanation The value of the variable angle is 5. Since 5 is less than 0, the condition of the third else if statement is true. Therefore, the value of angle will be 5  15 = 20.
Rate this question:
36.
Fill in the blank that will allow the program to display the numbers 2 to 20 in steps of two (i.e. 2,4,6, ..., 20) with one number per output line.int number = ____________ ;while (number <= 20) { cout << number << endl ; number = (number +2) ;} // end while
Correct Answer 2
Explanation The blank should be filled with "2" because the program starts with the number 2 and then increments it by 2 in each iteration of the while loop. This allows the program to display the numbers 2 to 20 in steps of two.
Rate this question:
37.
Fill in the blank that will allow the program to display the numbers 2 to 20 in steps of two (i.e. 2,4,6, ..., 20) with one number per output line.int number = 2 ;while (_______________) { cout << number << endl ; number = (number +2) ;} // end while
Correct Answer number <= 20
Explanation The blank should be filled with "number
Rate this question:
38.
Fill in the blank that will allow the program to display the numbers 2 to 20 in steps of two (i.e. 2,4,6, ..., 20) with one number per output line.int number = 2 ;while (number <= 20) { cout << _________<< endl ; number = (number +2) ;} // end while
Correct Answer number
Explanation The blank should be filled with "number" because the variable "number" is being printed in each iteration of the loop, and it is incremented by 2 in each iteration to display the numbers 2 to 20 in steps of two.
Rate this question:
39.
Fill in the blank that will allow the program to display the numbers 2 to 20 in steps of two (i.e. 2,4,6, ..., 20) with one number per output line.int number = 2 ;while (number <= 20) { cout << number << ________ ; number = (number +2) ;} // end while
Correct Answer endl
Explanation The correct answer is "endl" because using "endl" in the code will insert a new line after each number is displayed, resulting in one number per output line.
Rate this question:
40.
Fill in the blank that will allow the program to display the numbers 2 to 20 in steps of two (i.e. 2,4,6, ..., 20) with one number per output line.int number = 2 ;while (number <= 20) { cout << number << endl ; __________________ ;} // end while
Correct Answer number = number + 2 number = (number + 2)
Explanation The correct answer is "number = number + 2" or "number = (number + 2)". These statements increment the value of the variable "number" by 2 in each iteration of the while loop, allowing the program to display the numbers 2 to 20 in steps of two.
Rate this question:
41.
The following program is supposed to read 10 integer values using a loop, and find the sum total of those numbers. Fill in the blank to complete the program.int main () { int k, number ; int sum = 0 ; __________; while (k <= 10) { cout << "Enter a number: " ; cin >> number ; sum = sum + number ; k = k + 1 ; } // end while cout << "Result = " << sum << endl ; return 0;} //end main
Correct Answer k = 1
Explanation The variable "k" is initialized with a value of 1. This is important because it determines the condition for the while loop. The loop will continue as long as the value of "k" is less than or equal to 10. By setting "k" to 1, the loop will execute 10 times, allowing the program to read 10 integer values and calculate their sum.
Rate this question:
42.
The following program is supposed to read 10 integer values using a loop, and find the sum total of those numbers. Fill in the blank to complete the program.int main () { int k, number ; int sum = 0 ; k = 1 ; while (_________) { cout << "Enter a number: " ; cin >> number ; sum = sum + number ; k = k + 1 ; } // end while cout << "Result = " << sum << endl ; return 0;} //end main
Correct Answer k <= 10
Explanation The blank should be filled with "k
Rate this question:
43.
The following program is supposed to read 10 integer values using a loop, and find the sum total of those numbers. Fill in the blank to complete the program.int main () { int k, number ; int sum = 0 ; k = 1 ; while (k <= 10) { cout << "Enter a number: " ; ____________; sum = sum + number ; k = k + 1 ; } // end while cout << "Result = " << sum << endl ; return 0;} //end main
Correct Answer cin >> number
Explanation The blank should be filled with "cin >> number" because it is the statement that allows the user to input a number into the "number" variable. This statement is inside the while loop, which means it will be executed 10 times, allowing the user to input 10 integer values. The "number" variable is then added to the "sum" variable to calculate the total sum of the numbers.
Rate this question:
44.
The following program is supposed to read 10 integer values using a loop, and find the sum total of those numbers. Fill in the blank to complete the program.int main () { int k, number ; int sum = 0 ; k = 1 ; while (k <= 10) { cout << "Enter a number: " ; cin >> number ; __________________; k = k + 1 ; } // end while cout << "Result = " << sum << endl ; return 0;} //end main
Correct Answer sum = sum + number sum = (sum + number)
Explanation The correct answer is "sum = sum + number, sum = (sum + number)". Both of these options correctly update the value of the sum variable by adding the number variable to it. This ensures that the sum of all the numbers entered by the user is calculated correctly.
Rate this question:
45.
The following program is supposed to read 10 integer values using a loop, and find the sum total of those numbers. Fill in the blank to complete the program.int main () { int k, number ; int sum = 0 ; k = 1 ; while (k <= 10) { cout << "Enter a number: " ; cin >> number ; sum = sum + number ; k = k + 1 ; } // end while cout << "Result = " << ________<< endl ; return 0;} //end main
Correct Answer sum
Explanation The program uses a while loop to read 10 integer values from the user and adds them to the variable "sum". The variable "sum" keeps track of the total sum of the numbers entered. After the loop ends, the program outputs the value of "sum" as the result.
Rate this question:
46.
The C++ operator '&&' is classified as what?
A.
Relational
B.
Logical (Boolean)
C.
Neither
Correct Answer
B. Logical (Boolean)
Explanation The C++ operator '&&' is classified as Logical (Boolean) because it is used to perform logical AND operation on two boolean expressions. It returns true if both expressions evaluate to true, otherwise it returns false. This operator is commonly used in conditional statements and loops to make decisions based on multiple conditions.
Rate this question:
47.
The C++ operator ' ! ' is classified as what?
A.
Relational
B.
Logical (Boolean)
C.
Neither
Correct Answer
B. Logical (Boolean)
Explanation The C++ operator '!' is classified as Logical (Boolean) because it is used to perform logical negation. It returns the opposite of the boolean value of its operand. If the operand is true, the '!' operator will return false, and if the operand is false, it will return true. This operator is commonly used in conditional statements and loops to check for the opposite condition.
Rate this question:
48.
The C++ operator '&' is classified as what?
A.
Relational
B.
Logical (Boolean)
C.
Neither
Correct Answer
C. Neither
Explanation The C++ operator '&' is not classified as either a relational or logical (Boolean) operator. It is actually a bitwise operator. Bitwise operators perform operations on individual bits of binary numbers. The '&' operator is specifically used for bitwise AND operation, where it compares the corresponding bits of two numbers and produces a result with 1s in the positions where both bits are 1.
Rate this question:
49.
The C++ operator '>=' is classified as what?
A.
Relational
B.
Logical (Boolean)
C.
Neither
Correct Answer
A. Relational
Explanation The C++ operator '>=' is classified as a relational operator. Relational operators are used to compare two values and determine the relationship between them. The '>=' operator specifically checks if the value on the left is greater than or equal to the value on the right. This operator returns a boolean value of true if the condition is met, and false otherwise.
Rate this question:
50.
The C++ operator ' != ' is classified as what?
A.
Relational
B.
Logical (Boolean)
C.
Neither
Correct Answer
A. Relational
Explanation The C++ operator '!=' is classified as a relational operator. Relational operators are used to compare two values and return a Boolean value indicating whether the comparison is true or false. The '!=' operator specifically checks if two values are not equal to each other. Therefore, it falls under the category of relational operators.
Rate this question:
Quiz Review Timeline +
Our quizzes are rigorously reviewed, monitored and continuously updated by our expert board to maintain accuracy, relevance, and timeliness.