C++ Quiz 2

Approved & Edited by ProProfs Editorial Team
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 in-house 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.
Learn about Our Editorial Process
| By Tcarteronw
T
Tcarteronw
Community Contributor
Quizzes Created: 37 | Total Attempts: 31,024
Questions: 17 | Attempts: 1,179

SettingsSettingsSettings
C++ Quiz 2 - Quiz

.


Questions and Answers
  • 1. 

    Which of the following is not a valid identifier?

    • A.

      Return

    • B.

      MyInt

    • C.

      MyInteger

    • D.

      Total3

    Correct Answer
    A. Return
    Explanation
    The identifier "return" is not valid because it is a reserved keyword in many programming languages, including Java. Reserved keywords have special meanings in the language and cannot be used as identifiers for variables, functions, or classes.

    Rate this question:

  • 2. 

    What is the value of x after the following statements? int x; x = 0; x = x + 30;

    • A.

      0

    • B.

      30

    • C.

      33

    • D.

      Garbage

    Correct Answer
    B. 30
    Explanation
    The value of x is initially set to 0. Then, x is incremented by 30 using the statement "x = x + 30". Therefore, the final value of x is 30.

    Rate this question:

  • 3. 

    What is the output of the following code? float value; value = 33.5; cout << "value" << endl;

    • A.

      33.5

    • B.

      33

    • C.

      Value

    • D.

      Garbage

    Correct Answer
    C. Value
    Explanation
    The code initializes a variable "value" of type float and assigns it the value 33.5. The next line prints the string "value" followed by a newline character. Therefore, the output of the code is the string "value".

    Rate this question:

  • 4. 

    Which of the following lines correctly reads a value from the keyboard and stores it in the variable named myFloat?

    • A.

      Cin >> myFloat;

    • B.

      Cin

    • C.

      Cin >> "myFloat";

    • D.

      Cin >> myFloat >> endl;

    Correct Answer
    A. Cin >> myFloat;
    Explanation
    The correct answer is "cin >> myFloat;". This line of code uses the ">>" operator to read a value from the keyboard and store it in the variable named myFloat. The "cin" object is used to read input from the keyboard, and the ">>" operator is used to extract the input and store it in the variable.

    Rate this question:

  • 5. 

    Another way to write the value 3452211903 is

    • A.

      3.452211903e09

    • B.

      3.452211903e-09

    • C.

      3.452211903x09

    • D.

      3452211903e09

    Correct Answer
    A. 3.452211903e09
    Explanation
    The given answer, 3.452211903e09, represents the scientific notation of the value 3452211903. In scientific notation, a number is expressed as a decimal number between 1 and 10, multiplied by a power of 10. In this case, the decimal number is 3.452211903 and it is multiplied by 10 raised to the power of 9. This notation is commonly used to represent very large or very small numbers in a concise and standardized format.

    Rate this question:

  • 6. 

    What is the value of x after the following statements? float x; x = 15/4;

    • A.

      3.75

    • B.

      4.0

    • C.

      3.0

    • D.

      60

    Correct Answer
    C. 3.0
    Explanation
    The value of x after the given statements is 3.0. In the statement x = 15/4, the division operation is performed between two integers, which results in an integer division. In integer division, the decimal part is truncated, and only the whole number part is considered. Therefore, 15 divided by 4 equals 3 with a remainder of 3. The remainder is discarded, and the value assigned to x is the whole number part, which is 3.0 in this case.

    Rate this question:

  • 7. 

    What is the value of x after the following statements? int x; x = 15 %4;

    • A.

      15

    • B.

      4

    • C.

      3

    • D.

      3.75

    Correct Answer
    C. 3
    Explanation
    The value of x after the given statements is 3. The expression "15 % 4" calculates the remainder when 15 is divided by 4, which is 3. Therefore, the value of x is assigned as 3.

    Rate this question:

  • 8. 

    What is the value of x after the following statement? float x; x = 3.0 / 4.0 + 3  + 2 / 5

    • A.

      5.75

    • B.

      4.75

    • C.

      1.75

    • D.

      3.75

    Correct Answer
    D. 3.75
    Explanation
    The value of x is 3.75. In the given statement, the expression is evaluated from left to right. The first operation is 3.0 divided by 4.0, which equals 0.75. Then, 0.75 is added to 3, resulting in 3.75. Finally, 2 divided by 5 is 0.4, but since it is an integer division, the result is 0. Therefore, the final value of x is 3.75.

    Rate this question:

  • 9. 

    What is the value of x after the following statements? double x; x = 0; x += 3.0 * 4.0; x -= 2.0;

    • A.

      22.0

    • B.

      12.0

    • C.

      10.0

    • D.

      14.0

    Correct Answer
    C. 10.0
    Explanation
    The variable x is declared as a double and initialized with the value 0. Then, the value of x is updated by adding the result of multiplying 3.0 and 4.0, which is 12.0. Finally, the value of x is updated again by subtracting 2.0. Therefore, the final value of x is 10.0.

    Rate this question:

  • 10. 

    If x has the value of 3, y has the value of -2, and w is 10, is the following condition true or false? if( x < 2 && w < y)

    • A.

      True

    • B.

      False

    Correct Answer
    B. False
    Explanation
    The condition in the if statement is false because both parts of the logical operator && (AND) need to be true for the overall condition to be true. In this case, x is not less than 2, so the first part of the condition is false. Therefore, the overall condition is false.

    Rate this question:

  • 11. 

    What is the correct way to write the condition y < x < z?

    • A.

      (y < x < z)

    • B.

      ((y < x) && z)

    • C.

      ((y > x) || (y < z))

    • D.

      ((y < x) && (x < z))

    Correct Answer
    D. ((y < x) && (x < z))
    Explanation
    The correct way to write the condition y < x < z is ((y < x) && (x < z)). This is because the condition requires both y to be less than x and x to be less than z in order for it to be true. Using the logical AND operator (&&) ensures that both conditions must be satisfied for the overall condition to be true.

    Rate this question:

  • 12. 

    Given the following code fragment, what is the output? int x=5; if( x > 5)     cout << "x is bigger than 5. ";     cout <<"That is all. "; cout << "Goodbye\n";

    • A.

      X is bigger than 5. That is all

    • B.

      X is bigger than 5

    • C.

      That is all. Goodbye

    • D.

      Goodbye

    Correct Answer
    C. That is all. Goodbye
    Explanation
    The output of the code will be "That is all. Goodbye". This is because the condition in the if statement is false (x is not greater than 5), so the code inside the if statement will not be executed. The code after the if statement will be executed, which includes printing "That is all. " and "Goodbye".

    Rate this question:

  • 13. 

    Executing one or more statements one or more times is known as:

    • A.

      Selection

    • B.

      Iteration

    • C.

      Sequence

    • D.

      Algorithm

    Correct Answer
    B. Iteration
    Explanation
    Iteration refers to the process of executing one or more statements repeatedly. It involves the use of loops to repeatedly perform a set of instructions until a certain condition is met. This allows for efficient and controlled repetition of code, making it easier to handle tasks that require repeated execution. Therefore, iteration is the correct term for executing statements multiple times.

    Rate this question:

  • 14. 

    Given the following code fragment, what is the final value of y? int x, y; x = -1; y = 0; while(x <= 3) {     y += 2;     x += 1; }

    • A.

      2

    • B.

      10

    • C.

      6 6

    • D.

      8

    Correct Answer
    B. 10
    Explanation
    The code fragment initializes x to -1 and y to 0. Then, it enters a while loop that continues as long as x is less than or equal to 3. Inside the loop, y is incremented by 2 and x is incremented by 1. This process continues until x becomes 4, at which point the loop exits. Therefore, the final value of y is 10.

    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.

  • Current Version
  • Mar 21, 2023
    Quiz Edited by
    ProProfs Editorial Team
  • May 21, 2013
    Quiz Created by
    Tcarteronw
Advertisement
×

Wait!
Here's an interesting quiz for you.

We have other quizzes matching your interest.