C++ Programming Language Hardest Exam! Trivia Quiz

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: 38 | Total Attempts: 29,972
Questions: 90 | Attempts: 2,350

SettingsSettingsSettings
C++ Programming Language Hardest Exam! Trivia Quiz - Quiz

Below is what is considered the hardest trivia quiz on C++ programming language. It is designed for those of us who are studying towards passing the certification exam. Gaming developers mostly prefer the C++ language since it is fast. Are you feeling up to tackling this exam? Do give it a try and get to find out if you need more practice.


Questions and Answers
  • 1. 

    What is the output of the following function and function call? void calculateCost(int count, float& subTotal, float taxCost);   float tax = 0.0,   subtotal = 0.0;   calculateCost(15, subtotal,tax); cout << "The cost for 15 items is " << subtotal        << ", and the tax for " << subtotal << " is " << tax << endl; //end of fragment   void calculateCost(int count, float& subTotal, float taxCost) {       if ( count < 10)       {                   subTotal = count * 0.50;       }       else       {                   subTotal = count * 0.20;       }       taxCost = 0.1 * subTotal; }

    • A.

      The cost for 15 items is 3.00, and the tax for 3.00 is 0.30;

    • B.

      The cost for 15 items is 0.00, and the tax for 3.00 is 0.00;

    • C.

      The cost for 15 items is 0.00, and the tax for 3.00 is 0.30;

    • D.

      The cost for 15 items is 3.00, and the tax for 3.00 is 0.00;

    Correct Answer
    D. The cost for 15 items is 3.00, and the tax for 3.00 is 0.00;
    Explanation
    The function calculateCost takes in three parameters: count, subTotal, and taxCost. Inside the function, it checks if the count is less than 10. If it is, it multiplies the count by 0.50 and assigns the result to subTotal. If the count is not less than 10, it multiplies the count by 0.20 and assigns the result to subTotal. Then, it calculates the taxCost by multiplying 0.1 with the subTotal.

    In the given function call, calculateCost(15, subtotal, tax), the count is 15 which is not less than 10. Therefore, subTotal is calculated as 15 * 0.20 = 3.00. The taxCost is calculated as 0.1 * 3.00 = 0.30.

    So, the output of the function call is "The cost for 15 items is 3.00, and the tax for 3.00 is 0.30."

    Rate this question:

  • 2. 

    Which of the following is not an example of a program bug?

    • A.

      Run-time error

    • B.

      Operator error

    • C.

      Syntax error

    • D.

      Logic error

    Correct Answer
    B. Operator error
    Explanation
    An operator error refers to a mistake made by the user while interacting with a program, such as entering incorrect input or selecting the wrong option. It is not considered a program bug because it is not an issue with the program's code or functionality. Instead, it is a mistake made by the user that leads to unexpected or incorrect results. Program bugs, on the other hand, refer to errors or flaws in the program's code that cause it to behave incorrectly or produce incorrect results.

    Rate this question:

  • 3. 

    The set of instructions that a computer will follow is known as:

    • A.

      Hardware

    • B.

      Algorithm

    • C.

      Program

    • D.

      CPU

    Correct Answer
    C. Program
    Explanation
    A program refers to the set of instructions that a computer will follow. This set of instructions can be written in a programming language and is responsible for telling the computer what tasks to perform and how to perform them. It includes a series of steps that the computer executes in order to complete a specific task or achieve a desired outcome. Therefore, program is the correct answer as it accurately describes the set of instructions that a computer will follow.

    Rate this question:

  • 4. 

    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 a valid identifier because it is a reserved keyword in many programming languages. Reserved keywords have special meanings in the language and cannot be used as identifiers for variables, functions, or other elements in the code.

    Rate this question:

  • 5. 

    What is the value of x after the following statements? int x, y, z; y = 10; z = 3; x = y * z + 3;

    • A.

      Garbage

    • B.

      60

    • C.

      30

    • D.

      33

    Correct Answer
    D. 33
    Explanation
    The value of x is 33 because the expression y * z + 3 evaluates to 33. The value of y is 10 and the value of z is 3, so when we multiply y and z we get 30, and then we add 3 to get the final result of 33.

    Rate this question:

  • 6. 

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

    • A.

      0

    • B.

      30

    • C.

      33

    • D.

      Garbage

    Correct Answer
    D. Garbage
    Explanation
    The value of x is not initialized before the statement x = x + 30. Therefore, when this statement is executed, the value of x is undefined or garbage.

    Rate this question:

  • 7. 

    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
    A. 33.5
    Explanation
    The code initializes a variable named "value" with the value 33.5. Then, it prints the value of "value" followed by a line break. Therefore, the output of the code will be "33.5".

    Rate this question:

  • 8. 

    Which of the following statements is NOT legal?

    • A.

      Char ch='b';

    • B.

      Char ch='0';

    • C.

      Char ch=65;

    • D.

      Char ch="cc";

    Correct Answer
    D. Char ch="cc";
    Explanation
    The statement "char ch="cc";" is not legal because it is assigning a string value to a char variable. In C++, a char variable can only store a single character, not a string of characters.

    Rate this question:

  • 9. 

    An algorithm is

    • A.

      The inputs and outputs of a program

    • B.

      The part of the computer that does the processing

    • C.

      A finite set of steps to solve a problem

    • D.

      A complete computer program

    Correct Answer
    C. A finite set of steps to solve a problem
    Explanation
    The correct answer is "A finite set of steps to solve a problem". This answer accurately describes an algorithm, which is a precise and unambiguous set of instructions or steps that can be followed to solve a specific problem or perform a specific task. An algorithm can be implemented in any programming language and is independent of the inputs and outputs of a program, the processing unit of a computer, or being a complete computer program.

    Rate this question:

  • 10. 

    Which of the following is not a phase of the program-design process?

    • A.

      Problem-solving

    • B.

      Implementation

    • C.

      Marketing the final program

    Correct Answer
    C. Marketing the final program
    Explanation
    The program-design process consists of several phases, including problem-solving, implementation, and marketing the final program. However, marketing the final program is not considered a phase of the program-design process. This phase typically occurs after the program has been designed and developed, and it involves promoting and advertising the program to potential users or customers. It focuses on creating awareness and generating interest in the program, rather than the actual design and development of the program itself.

    Rate this question:

  • 11. 

    Which of the following is not part of the Software Life Cycle?

    • A.

      Analysis

    • B.

      Design

    • C.

      Data Entry

    • D.

      Implementation

    • E.

      Testing

    Correct Answer
    C. Data Entry
    Explanation
    Data Entry is not part of the Software Life Cycle because it refers to the process of inputting data into a computer system, which is not a specific phase or activity in the software development process. The Software Life Cycle typically includes phases such as Analysis, Design, Implementation, and Testing, which are essential steps in developing and deploying software applications. Data Entry, on the other hand, is a separate task that involves entering data into a system, but it is not directly related to the overall software development process.

    Rate this question:

  • 12. 

    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 4. The expression "15 % 4" calculates the remainder when 15 is divided by 4, which is 3. Therefore, x is assigned the value of 3.

    Rate this question:

  • 13. 

    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. This is because the expression on the right side of the assignment operator (=) is evaluated from left to right. First, the division 3.0 / 4.0 is performed, resulting in 0.75. Then, the addition 0.75 + 3 is calculated, giving 3.75. Finally, the division 2 / 5 is performed, resulting in 0.4, but since x is declared as a float, the decimal part is retained, giving the final value of 3.75.

    Rate this question:

  • 14. 

    1. Which boolean operation is described by the following table?
    A B Operation True True True True False True False True True False False False

    • A.

      Or

    • B.

      And

    • C.

      Not

    • D.

      None of the above

    Correct Answer
    A. Or
    Explanation
    The correct answer is "or". This is because the operation returns "True" when at least one of the inputs is "True". In the given table, whenever either A or B is "True", the result is "True". Only when both A and B are "False", the result is "False".

    Rate this question:

  • 15. 

    Which of the following data types may be used in a switch statement?

    • A.

      Int

    • B.

      Char

    • C.

      Enum

    • D.

      Long

    • E.

      All answers are correct

    Correct Answer
    E. All answers are correct
    Explanation
    In a switch statement, any of the given data types (int, char, enum, long) can be used. This is because a switch statement allows for multiple cases to be evaluated, and these data types can all be used as the expression to evaluate the cases. Therefore, all of the given answers are correct.

    Rate this question:

  • 16. 

    What is wrong with the following for loop?       for(int i=0; i<10; i--)       {                   cout << "Hello\n";       }

    • A.

      Can not use a for-loop for this

    • B.

      I is not initialized

    • C.

      Infinite loop

    • D.

      Off-by-one error

    Correct Answer
    C. Infinite loop
    Explanation
    The given for loop is an infinite loop because the condition for the loop to continue is i < 10, but inside the loop, the value of i is decremented by i--. This means that i will never be greater than or equal to 10, causing the loop to run indefinitely.

    Rate this question:

  • 17. 

    What is the value of x after the following code fragment executes? float x = 36.0; x = sqrt(x);

    • A.

      36.0

    • B.

      6.0

    • C.

      3.0

    • D.

      2.456

    Correct Answer
    B. 6.0
    Explanation
    The code fragment starts by initializing the variable x with the value 36.0. Then, the sqrt() function is applied to x, which calculates the square root of x. The square root of 36.0 is 6.0. Therefore, the value of x after the code fragment executes is 6.0.

    Rate this question:

  • 18. 

    What is the output of the following program fragment? cout << pow(4,2) << endl;

    • A.

      4

    • B.

      2

    • C.

      8

    • D.

      16

    Correct Answer
    D. 16
    Explanation
    The program fragment uses the pow() function to calculate the result of raising 4 to the power of 2. The pow() function takes two arguments, the base (4 in this case) and the exponent (2 in this case), and returns the result of the exponentiation. The result, 16, is then printed to the console followed by a newline character.

    Rate this question:

  • 19. 

    Which boolean operation is described by the following table? A B Operation True True True True False False False True False False False False  

    • A.

      Or

    • B.

      And

    • C.

      Not

    • D.

      None of the above

    Correct Answer
    B. And
    Explanation
    The given table represents the boolean operation "and". In this operation, the result is true only when both inputs are true. In all other cases, the result is false.

    Rate this question:

  • 20. 

    When overloading a function, what must be true?

    • A.

      The names should be different with the same number and/or types of parameters.

    • B.

      The names should be the same with different number and/or types of parameters.

    • C.

      The names should be different with different number and/or types of parameters.

    • D.

      The names should be the same with the same number and/or types of parameters.

    Correct Answer
    B. The names should be the same with different number and/or types of parameters.
    Explanation
    When overloading a function, the names of the functions should be the same, but the number and/or types of parameters should be different. This allows multiple functions with the same name to be defined, but with different parameter lists. This enables the programmer to perform different operations based on the arguments passed to the function.

    Rate this question:

  • 21. 

    When parameters are passed between the calling code and the called function, parameters and arguments are matched by:

    • A.

      Their data types

    • B.

      Their relative positions in the parameter and argument lists

    • C.

      Their names

    • D.

      They are not matched up at all.

    Correct Answer
    B. Their relative positions in the parameter and argument lists
    Explanation
    When parameters are passed between the calling code and the called function, the matching of parameters and arguments is based on their relative positions in the parameter and argument lists. This means that the first parameter in the parameter list will be matched with the first argument in the argument list, the second parameter with the second argument, and so on. The order in which the parameters and arguments are listed is crucial for the correct matching to occur.

    Rate this question:

  • 22. 

    The expression static_cast(3) is called a

    • A.

      Type cast

    • B.

      Multiplier

    • C.

      Doubler

    • D.

      Polymorphism

    Correct Answer
    A. Type cast
    Explanation
    The expression static_cast(3) is called a type cast. Type casting is a way to convert one data type into another. In this case, the static_cast is used to explicitly convert the value 3 into a different type.

    Rate this question:

  • 23. 

    What is the value of the following? sqrt(pow(2,4));

    • A.

      1

    • B.

      2

    • C.

      4

    • D.

      16

    Correct Answer
    C. 4
    Explanation
    The given expression calculates the square root of the result of raising 2 to the power of 4. In other words, it calculates the square root of 16. The square root of 16 is 4.

    Rate this question:

  • 24. 

    Information Hiding is analogous to using

    • A.

      An algorithmic design

    • B.

      A black-box methodology

    • C.

      Actual parameters

    Correct Answer
    B. A black-box methodology
    Explanation
    Information hiding is analogous to using a black-box methodology because both involve the concept of encapsulating details and complexity. In information hiding, the internal workings of a module or object are hidden from the outside world, allowing for easier maintenance and modification. Similarly, in a black-box methodology, the inner workings of a system or process are not visible or accessible, and only the inputs and outputs are considered. Both approaches promote abstraction and modularization, making it easier to understand and work with complex systems.

    Rate this question:

  • 25. 

    What is the output of the following function call? //function body int factorial(int n) {       int product=0;       while(n > 0)       {                   product = product * n;                   n—;       }       return product; }   //function call cout << factorial(4);

    • A.

      4

    • B.

      0

    • C.

      24

    • D.

      48

    Correct Answer
    B. 0
    Explanation
    The output of the function call factorial(4) is 0. This is because the variable "product" is initialized to 0 and is never updated within the while loop. Therefore, when the loop ends, the value of "product" remains 0 and is returned as the output.

    Rate this question:

  • 26. 

    Which of the following are equivalent to (!(x<15 && y>=3))?

    • A.

      (x>15 && y

    • B.

      (x>=15 && y < 3)

    • C.

      (x>=15 || y < 3)

    • D.

      (x>15 || y < 3)

    Correct Answer
    C. (x>=15 || y < 3)
    Explanation
    The given expression is a negation of (x=3). In other words, it is equivalent to the opposite of (x=3). The opposite of (x=3) is (x>=15 || y=15 || y

    Rate this question:

  • 27. 

    Given the following code, what is the final value of i?       int i,j;       for(i=0;i<4;i++)       {                   for(j=0;j<3;j++)                   {                               if(i==2)                                           break;                   }       }

    • A.

      3

    • B.

      4

    • C.

      5

    • D.

      0

    Correct Answer
    B. 4
    Explanation
    The final value of i is 4. The outer loop iterates 4 times (i=0, i=1, i=2, i=3), and the inner loop iterates 3 times for each iteration of the outer loop. However, when i=2, the inner loop is terminated with the break statement. Therefore, the inner loop only runs twice when i=2. As a result, i reaches its final value of 4.

    Rate this question:

  • 28. 

    What is the value returned by the following function? int function() {       int value = 35;       return value + 5;       value += 10; }

    • A.

      35

    • B.

      40

    • C.

      50

    • D.

      10

    Correct Answer
    B. 40
    Explanation
    The function returns the value of "value" variable plus 5, which is 40. The code after the return statement is not executed, so the line "value += 10;" does not affect the returned value.

    Rate this question:

  • 29. 

    If you need to write a function that will compute the cost of some candy, where each piece costs 25 cents, which would be an appropriate function declaration?

    • A.

      Int calculateCost(char name);

    • B.

      Char calculateCost(int count);

    • C.

      Int calculateCost int count;

    • D.

      Int calculateCost(int count);

    Correct Answer
    D. Int calculateCost(int count);
    Explanation
    The appropriate function declaration for computing the cost of candy would be "int calculateCost(int count);" because it takes an integer parameter "count" which represents the number of candy pieces, and it returns an integer value representing the total cost in cents. The other function declarations are not suitable because they either have the wrong parameter type or missing parameter type.

    Rate this question:

  • 30. 

    When a variable is local to a function, we say that it has ___ of the function

    • A.

      Value

    • B.

      Constance

    • C.

      Scope

    • D.

      Locality

    Correct Answer
    C. Scope
    Explanation
    When a variable is local to a function, it means that it can only be accessed and used within that specific function. This concept is known as the scope of the variable. The scope defines the visibility and accessibility of the variable, ensuring that it does not interfere with other variables outside of the function. Therefore, the correct answer is "scope".

    Rate this question:

  • 31. 

    Testing your program should be done

    • A.

      As each function is developed

    • B.

      At the end of the coding

    • C.

      Only if there appear to be problems

    • D.

      Only if your instructor requires it.

    Correct Answer
    A. As each function is developed
    Explanation
    Testing your program should be done as each function is developed because it allows for early detection and resolution of any issues or bugs that may arise during the development process. By testing each function individually, it becomes easier to isolate and identify any errors, making the debugging process more efficient. Additionally, testing at this stage helps ensure that each function works correctly before moving on to the next one, ultimately leading to a more robust and reliable final program.

    Rate this question:

  • 32. 

    What is wrong with the following code? int f1( int x, int y) {             x = y * y;             return x;             int f2( float a, float& b) {             if(a < b)                         b = a;             else                         a=b;             return 0.0;        } }

    • A.

      Neither function should return a value

    • B.

      Function definitions may not be nested

    • C.

      Both parameters to f2 should be pass-by reference

    • D.

      In f2, a can not be assigned b.

    • E.

      Nothing is wrong

    Correct Answer
    B. Function definitions may not be nested
    Explanation
    The given code contains two function definitions, f1 and f2, which are nested within each other. However, in C++ (and most programming languages), function definitions cannot be nested. Each function should be defined separately and not within another function. This is why the correct answer is "Function definitions may not be nested."

    Rate this question:

  • 33. 

    If a function needs to modify more than one variable, it must

    • A.

      Be pass by value

    • B.

      Be a void function

    • C.

      Return all values needed

    • D.

      Be a call by reference function

    Correct Answer
    D. Be a call by reference function
    Explanation
    If a function needs to modify more than one variable, it must be a call by reference function. This is because call by reference allows the function to directly access and modify the original variables, rather than creating copies of them. By passing the variables by reference, any changes made within the function will be reflected in the original variables outside of the function. This is necessary when multiple variables need to be modified within a function.

    Rate this question:

  • 34. 

    When a void function is called, it is known as

    • A.

      An output function.

    • B.

      A returned value.

    • C.

      An executable statement.

    • D.

      A comment

    Correct Answer
    C. An executable statement.
    Explanation
    When a void function is called, it is known as an executable statement because it performs a specific task or action within the program. Unlike functions that return a value, a void function does not provide any output or returned value. Instead, it executes a series of statements or commands to carry out a particular operation. Therefore, calling a void function is considered an executable statement within the program's flow of execution.

    Rate this question:

  • 35. 

    Call-by-reference should be used

    • A.

      For all variables

    • B.

      When the function needs to change the value of one or more arguments

    • C.

      Never

    • D.

      Only in void functions

    Correct Answer
    B. When the function needs to change the value of one or more arguments
    Explanation
    Call-by-reference should be used when the function needs to change the value of one or more arguments. This is because call-by-reference allows the function to directly access and modify the original variables passed as arguments, rather than creating copies of them. By using call-by-reference, any changes made to the arguments inside the function will be reflected outside of the function as well. This is particularly useful when the function needs to update the values of variables in the calling code.

    Rate this question:

  • 36. 

    A simplified main program used to test functions is called

    • A.

      A stub

    • B.

      Abstraction

    • C.

      Polymorphism

    • D.

      A driver

    Correct Answer
    A. A stub
    Explanation
    A stub is a simplified main program used to test functions. It is a placeholder that simulates the behavior of a real program or function, allowing developers to test individual components before integrating them into the larger system. Stubs are often used when certain dependencies or components are not yet implemented or available, allowing developers to focus on testing specific functionality without the need for a complete and fully functional program.

    Rate this question:

  • 37. 

    x = 10; y = 15; mystery(x, y); void mystery (int& one, int two) {      int temp;      temp = one;      one = two;      two = temp; } What are the values of x and y after the statements above execute? (Assume that variables are properly declared.)

    • A.

      X = 10; y = 10

    • B.

      X = 10; y = 15

    • C.

      X = 15; y = 10

    • D.

      X = 15; y = 15

    • E.

      None are correct

    Correct Answer
    D. X = 15; y = 15
    Explanation
    The values of x and y after the statements above execute are x = 15 and y = 15. This is because the mystery function swaps the values of the two input parameters. So, the value of x becomes equal to the initial value of y (which is 15) and the value of y becomes equal to the initial value of x (which is also 15).

    Rate this question:

  • 38. 

    A function that is associated with an object is called a _________ function.

    • A.

      Input

    • B.

      Output

    • C.

      Member

    • D.

      Instantiated

    Correct Answer
    C. Member
    Explanation
    A function that is associated with an object is called a member function. This type of function is defined within a class and can access the object's data members and other member functions. It is used to perform specific operations or actions on the object.

    Rate this question:

  • 39. 

    After a stream is opened, before it is used for input and output, it should be

    • A.

      Declared

    • B.

      Closed

    • C.

      Checked to see if it opened correctly

    • D.

      None of the above

    Correct Answer
    C. Checked to see if it opened correctly
    Explanation
    Before a stream is used for input and output, it should be checked to see if it opened correctly. This is important because if the stream did not open successfully, attempting to use it for input and output operations may result in errors or unexpected behavior. By checking if the stream opened correctly, any potential issues can be identified and handled appropriately before proceeding with further operations.

    Rate this question:

  • 40. 

    If the user types in the characters 10, and your program reads them into an integer variable, what is the value stored into that integer?

    • A.

      1

    • B.

      0

    • C.

      10

    • D.

      None of the above

    Correct Answer
    C. 10
    Explanation
    When the user types in the characters "10", the program reads them into an integer variable. Since the characters "10" represent the numeric value of ten, the value stored into that integer variable will be 10.

    Rate this question:

  • 41. 

    What is the output of the following code? char ch='G'; cout << tolower(ch) << endl; 

    • A.

      G

    • B.

      G

    • C.

      The integer value of 'g'

    • D.

      The integer value of 'G'

    Correct Answer
    C. The integer value of 'g'
    Explanation
    The output of the code is the integer value of 'g'. The function tolower() is used to convert the character 'G' to its lowercase equivalent, which is 'g'. The lowercase 'g' is then printed to the console.

    Rate this question:

  • 42. 

    A simplified version of a function which is used to test the main program is called

    • A.

      A stub

    • B.

      Abstraction

    • C.

      Polymorphism

    • D.

      A driver

    Correct Answer
    A. A stub
    Explanation
    A simplified version of a function used to test the main program is called a stub. A stub is a placeholder or a temporary implementation of a function that allows the main program to be tested without fully implementing all the functionality. It provides a basic structure or interface for the function, allowing the program to compile and run, but the actual logic or implementation of the function is not fully developed. Stubs are commonly used in software development to simulate the behavior of complex functions or modules during testing.

    Rate this question:

  • 43. 

    When a void function is called, it is known as

    • A.

      An output function.

    • B.

      A returned value

    • C.

      An executable statement

    • D.

      A comment

    Correct Answer
    C. An executable statement
    Explanation
    When a void function is called, it is known as an executable statement because it performs a specific task or action when it is executed. Unlike functions that return a value, void functions do not have a return type and therefore do not return any value. Instead, they are used to perform actions or operations without returning a result.

    Rate this question:

  • 44. 

    The following code: int *p; declares p to be a(n) ____ variable.

    • A.

      New

    • B.

      Num

    • C.

      Pointer

    • D.

      Address

    Correct Answer
    C. Pointer
    Explanation
    The given code declares a variable named "p" to be a pointer. A pointer is a variable that stores the memory address of another variable. In this case, "p" is declared as a pointer to an integer, as indicated by the use of the "*" symbol before the variable name.

    Rate this question:

  • 45. 

    Given the following statements: int x = 25; int *p = &x; *p = 46; what is the value of x?

    • A.

      Null

    • B.

      0

    • C.

      25

    • D.

      46

    Correct Answer
    D. 46
    Explanation
    The value of x is 46 because the variable p is a pointer that points to the memory address of x. By dereferencing the pointer using the * operator, the value at that memory address is changed to 46. Therefore, the value of x is also updated to 46.

    Rate this question:

  • 46. 

    In C++, you declare a pointer variable by using the ____ symbol.

    • A.

      *

    • B.

      &

    • C.

      #

    • D.

      @

    Correct Answer
    A. *
    Explanation
    In C++, you declare a pointer variable by using the "*" symbol. The "*" symbol is used to indicate that a variable is a pointer and can store the memory address of another variable. This allows you to indirectly access and manipulate the value of the variable that the pointer is pointing to.

    Rate this question:

  • 47. 

    Double sales [50]; int j; Consider the declaration above. Which of the following correctly initializes the array sales?

    • A.

      For(j = 0; j

    • B.

      For(j = 1; j

    • C.

      For(j = 0; j

    • D.

      For(j = 1; j

    Correct Answer
    C. For(j = 0; j
    Explanation
    The correct answer is "for(j = 0; j < 50; j++)". This initializes the array sales with a loop that starts from 0 and goes up to 49 (50 times in total), incrementing the value of j by 1 each time. This ensures that each element of the array is assigned a value.

    Rate this question:

  • 48. 

    X = 10; y = 15; mystery (x, y); void mystery(int& one, int two) {      int temp;      temp = one;      one = two;      two = temp; } What are the values of x and y after the statements above execute? (Assume that variables are properly declared.)

    • A.

      X = 10; y = 10

    • B.

      X = 10; y = 15

    • C.

      X = 15; y = 10

    • D.

      X = 15; y = 15

    Correct Answer
    D. X = 15; y = 15
    Explanation
    The values of x and y after the statements above execute are x = 15 and y = 15. This is because the function "mystery" swaps the values of the two input variables. In this case, the initial values of x and y are 10 and 15 respectively. After the function is called, the value of x becomes 15 (which was the initial value of y) and the value of y becomes 15 (which was the initial value of x).

    Rate this question:

  • 49. 

    Cout << fixed << showpoint; cout <<setprecision(2); cout << x << " "  << y << " " << z << endl; Suppose that x = 25.67, y = 356.876, and z = 7623.9674. What is the output of the above statements?

    • A.

      25.67 356.87 7623.96

    • B.

      25.67 356.87 7623.97

    • C.

      25.67 356.88 7623.97

    • D.

      25.67 356.876 7623.967

    Correct Answer
    C. 25.67 356.88 7623.97
    Explanation
    The code snippet uses the fixed manipulator to set the floating-point output format to fixed-point notation. The showpoint manipulator ensures that the decimal point is always displayed, even if there are no decimal places. The setprecision(2) function sets the precision of the output to 2 decimal places. Therefore, when the values of x, y, and z are printed using cout, they will be displayed with 2 decimal places. The correct answer is "25.67 356.88 7623.97" because it matches the expected output format.

    Rate this question:

  • 50. 

    C++ programs should contain comments to explain the code.

    • A.

      True

    • B.

      False

    Correct Answer
    A. True
    Explanation
    Including comments in C++ programs is considered good practice because it helps in understanding and explaining the code. Comments provide additional information about the purpose, functionality, and logic of the code, making it easier for other developers (or even the original developer) to read and maintain the code. They can also serve as documentation for future reference. Therefore, it is recommended to include comments in C++ programs to enhance code readability and maintainability.

    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
  • Feb 05, 2024
    Quiz Edited by
    ProProfs Editorial Team
  • May 11, 2011
    Quiz Created by
    Tcarteronw
Back to Top Back to top
Advertisement
×

Wait!
Here's an interesting quiz for you.

We have other quizzes matching your interest.