C++ Programming Language Hardest Exam! Trivia 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 Tcarteronw
T
Tcarteronw
Community Contributor
Quizzes Created: 38 | Total Attempts: 32,005
| Attempts: 2,604 | Questions: 90
Please wait...
Question 1 / 90
0 %
0/100
Score 0/100
1. (T   F)  Another way to created a running total other than total = total + num is to write total += num.

Explanation

The statement is true because the expression "total += num" is a shorthand way of writing "total = total + num". Both expressions will achieve the same result of updating the value of the variable "total" by adding the value of "num" to it.

Submit
Please wait...
About This Quiz
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.... see moreGaming 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. see less

2. A library is a collection of program code that can be used by other programs.

Explanation

A library is a collection of program code that can be used by other programs. This means that libraries contain pre-written code that can be utilized by developers in their own programs, saving them time and effort. By using libraries, developers can access functions, classes, or modules that have already been created and tested, allowing them to focus on other aspects of their program. Therefore, the statement "A library is a collection of program code that can be used by other programs" is true.

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

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.

Submit
4. (T  F)  The following symbols represent OR:   &&.

Explanation

The statement is false because the symbols "&&" represent AND, not OR. OR is represented by the symbol "||".

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

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.

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

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.

Submit
7. C++ is not case-sensitive.

Explanation

C++ is actually case-sensitive, meaning that it distinguishes between uppercase and lowercase letters. This means that variables, functions, and other identifiers must be written with consistent capitalization in order for the program to compile correctly. For example, "myVariable" and "myvariable" would be considered as two separate identifiers in C++. Therefore, the correct answer is False.

Submit
8. Str1 = "abc"; str2 = "xyz"; str3 = str1 + "-" +str2; Suppose that str1, str2, and str3 are string variables. After the statements above execute, the value of str3 is "_____".

Explanation

The given code declares three string variables, str1, str2, and str3. The value of str1 is "abc" and the value of str2 is "xyz". The code then concatenates str1, a hyphen "-", and str2 together using the + operator and assigns the resulting string to str3. So, after the statements execute, the value of str3 is "abc-xyz".

Submit
9. An "if" structure inside another "if" structure is called a:

Explanation

A nested if structure refers to an if statement that is placed inside another if statement. It allows for more complex decision-making by providing multiple levels of conditions to be evaluated. This can be useful when certain conditions need to be met before checking additional conditions. By nesting if statements, the program can execute different blocks of code based on the combination of conditions being true or false.

Submit
10. (T  F) A function is invoked by a function call.

Explanation

A function is a block of code that performs a specific task. It can be invoked or called by using its name followed by parentheses. When a function is invoked, the program jumps to that function and executes the code inside it. Therefore, a function is indeed invoked by a function call.

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

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.

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

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".

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

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.

Submit
14. When you type int main( ), it means that an integer will be returned.

Explanation

When you type "int main( )", it means that the main function will return an integer value. In C++ and some other programming languages, the main function is the entry point of the program, and it is expected to return an integer value to indicate the status of the program execution. Therefore, the statement "an integer will be returned" is correct.

Submit
15. A variable assigned int can produce a number with decimals.

Explanation

A variable assigned int cannot produce a number with decimals because int is a data type that represents whole numbers only. If we need to store numbers with decimals, we would use a different data type such as float or double.

Submit
16. An algorithm is

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.

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

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.

Submit
18. Call-by-reference should be used

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.

Submit
19. The statement num is less than 10 or num is greater than 50 in C++ is written as _____.

Explanation

The correct answer is "num < 10 || num > 50". This is the correct way to write the statement "num is less than 0 or num is greater than 50" in C++. The "||" operator is the logical OR operator, which checks if either condition is true. In this case, it checks if num is less than 10 or if num is greater than 50.

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

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.

Submit
21. The identifiers in the system-provided header files such as iostream, cmath, and iomanip are defined in the namespace _____.

Explanation

The identifiers in the system-provided header files such as iostream, cmath, and iomanip are defined in the "std" namespace. The "std" namespace is used to avoid naming conflicts and to organize the code in a structured manner. By using the "std" namespace, the identifiers in these header files can be accessed using the scope resolution operator "::".

Submit
22. Assume you have the following declaration char nameList[100];. Which of the following ranges is valid for the index of the array nameList?

Explanation

The valid range for the index of the array nameList is from 0 through 99. This is because arrays in C/C++ are zero-indexed, meaning the first element of the array is at index 0 and the last element is at index n-1, where n is the size of the array. In this case, the array nameList has a size of 100, so the valid index range is from 0 to 99.

Submit
23. What is the output produced by the following segment of code? int x, y; y = 123; x = y + y; y = 19; cout << " x = " << x; cout << " y = " << y;

Explanation

The code initializes two variables, x and y. It assigns the value 123 to y. Then, it assigns the value of y + y (which is 123 + 123 = 246) to x. After that, it assigns the value 19 to y. Finally, it prints the values of x and y. Therefore, the output will be "x = 246 y = 19".

Submit
24.
  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

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".

Submit
25. 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?

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.

Submit
26. The expression static_cast(3) is called a

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.

Submit
27. 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?

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.

Submit
28. It is possible when using a while loop that the body of the loop will never be executed.

Explanation

In a while loop, the condition is evaluated before each iteration. If the condition is initially false, the body of the loop will never be executed. This can happen when the condition is set to an expression that is always false or when the loop control variable is not properly updated within the loop. Therefore, it is possible for the body of a while loop to never be executed.

Submit
29. A cin statement sends output to the computer screen.

Explanation

The cin statement is used in programming languages like C++ to take input from the user, not to send output to the computer screen. It is used to read data from the standard input stream, which can be the keyboard or a file. Therefore, the given statement is incorrect, and the correct answer is False.

Submit
30. Testing your program should be done

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.

Submit
31. If an & is attached after the data type of a formal parameter, then the formal parameter is a _____.

Explanation

If an "&" is attached after the data type of a formal parameter, it indicates that the formal parameter is a reference parameter. This means that the parameter will not create a new copy of the data when passed to a function, but rather it will refer to the same memory location as the argument that is passed to it. Any changes made to the reference parameter within the function will also affect the original argument outside of the function.

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

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.

Submit
33. Which of the following would allow you to move to the next line:

Explanation

In C++ programming, the << endl; command is used to insert a newline character, which moves the output to the next line. This effectively ends the current line of text and starts a new one, similar to \n, but endl also flushes the output buffer. 

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

Explanation

The given for loop is an infinite loop because the condition for the loop to continue is i

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

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.

Submit
36. Consider the following statement: double alpha[10][5];. The number of components of alpha is _____.

Explanation

The statement "double alpha[10][5];" declares a 2-dimensional array called alpha with 10 rows and 5 columns. The number of components in the array can be calculated by multiplying the number of rows by the number of columns, which is 10 * 5 = 50. Therefore, the correct answer is 50.

Submit
37. The break statement:

Explanation

The break statement is used in programming to immediately terminate the current block of code. It is often used in loops or switch statements to exit the loop or skip the remaining code in the block. This allows the program to jump to the next statement after the loop or switch, effectively terminating the current block of code. It does not terminate the entire program or cause an infinite loop.

Submit
38. When a void function is called, it is known as

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.

Submit
39. When a void function is called, it is known as

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.

Submit
40. (T   F)  A program can still run if it has a warning error.

Explanation

A program can still run if it has a warning error because warning errors are not critical and do not prevent the program from executing. Warning errors are typically issued by the compiler or IDE to alert the programmer about potential issues or best practices that should be followed. While it is recommended to address warning errors to ensure the program is optimized and error-free, they do not hinder the program's functionality and execution.

Submit
41. What is the value of the following? sqrt(pow(2,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.

Submit
42. If x is a char variable, which of the following are legal assignment statements:

Explanation

The given answer is correct because it assigns the character 'c' to the variable x, which is a char variable. In C++, single quotes are used to represent individual characters, so 'c' is a valid assignment statement for a char variable. The other options are not valid because assigning a string literal or a variable of a different data type to a char variable would result in a type mismatch.

Submit
43. (T   F)  A semicolon is always placed after the condition of an if statement.

Explanation

A semicolon is not always placed after the condition of an if statement. In most programming languages, including languages like C, C++, Java, and Python, a semicolon is not required after the condition of an if statement. The semicolon is only used to terminate a statement, and the condition of an if statement is not considered a separate statement. Therefore, it is not necessary to include a semicolon after the condition of an if statement.

Submit
44. Which of the following is not part of the Software Life Cycle?

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.

Submit
45. Information Hiding is analogous to using

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.

Submit
46. Cin >> num; if (num > 0)     num = num + 10; else    if (num >= 5)       num = num + 15; After the execution of the code above, what will be the value of num if the input value is 5?

Explanation

The value of num will be 15 if the input value is 5. This is because the input value is not greater than 0, so the else statement is executed. Since the input value is equal to 5, the condition num >= 5 is true and the value of num is increased by 15. Therefore, the final value of num is 15.

Submit
47. // will allow you to make a multiple line comment.

Explanation

The given correct answer is "False". This is because the statement "// will allow you to make a multiple line comment." is incorrect. In most programming languages, the syntax for making a multiple line comment is different, and using "//" typically indicates a single line comment instead. Therefore, the answer is false as "//" does not allow for multiple line comments.

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

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.

Submit
49. Libraries are included after the main function.

Explanation

In C programming, libraries are typically included before the main function using the #include directive. This allows the program to access any necessary functions or definitions from the library. Including libraries after the main function would result in compilation errors as the program would not recognize the library functions. Therefore, the given statement is false.

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

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.

Submit
51. 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? (assume you have included iomanip)

Explanation

The code snippet uses the "fixed" and "showpoint" manipulators to display floating-point numbers in fixed-point notation with a decimal point. It then sets the precision to 2 decimal places using the "setprecision" function.

Given that x = 25.67, y = 356.876, and z = 7623.9674, the output will be 25.67 (unchanged), 356.88 (rounded to 2 decimal places), and 7623.97 (rounded to 2 decimal places). Therefore, the correct answer is "25.67 356.88 7623.97".

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

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.

Submit
53. Which of the following is not a valid identifier?

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.

Submit
54. 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?

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.

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

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.

Submit
56. By using a \", you can create a quotation mark inside of a string.

Explanation

By using a \”, you can create a quotation mark inside of a string. This statement is true. In programming languages, the backslash (\) is often used as an escape character to indicate that the following character has a special meaning. In this case, the \” is used to represent a quotation mark within a string. This allows programmers to include quotation marks as part of the string without causing syntax errors or confusion with the surrounding code.

Submit
57. Suppose that alpha is a double variable. Choose the value of alpha after the following statement executes: alpha = 12.5 + static_cast<double>(13) / 2;.

Explanation

The statement alpha = 12.5 + static_cast(13) / 2; calculates the value of alpha by adding 12.5 to the result of dividing 13 by 2. Since 13 divided by 2 is 6.5, the result of the expression is 12.5 + 6.5 = 19.0. Therefore, the value of alpha after the statement executes is 19.0.

Submit
58. Which of the following statements is NOT legal?

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.

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

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.

Submit
60. 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.)

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).

Submit
61. A variable listed in a function call is known as a(n) _____ parameter.  A variable list in a header is known as a(n) _____ parameter.

Explanation

In a function call, the variables that are passed as arguments are known as actual parameters. These actual parameters are the values that are actually used in the function. On the other hand, in a function header, the variables that are declared as placeholders for the values to be passed are known as formal parameters. These formal parameters act as variables within the function and are assigned the values of the actual parameters when the function is called. Therefore, the correct answer is "actual; formal".

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

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.

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

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.

Submit
64. A simplified main program used to test functions is called

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.

Submit
65. Before using the data type string, the program must include the header file _____.

Explanation

Before using the data type string, the program must include the header file "string". This is because the string data type is a part of the standard library in C++, and in order to use it, the program needs to include the appropriate header file. By including the "string" header file, the program can access the necessary functions and classes related to strings.

Submit
66. X = 6 if (x > 10)    cout << " One " ;    cout << " Two " ;

Explanation

The given code first assigns the value 6 to the variable x. Then, it checks if the value of x is greater than 10. Since 6 is not greater than 10, the condition evaluates to false and the code inside the if statement is not executed. Therefore, the program moves on to the next line of code which is "cout

Submit
67. 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.)

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).

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

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.

Submit
69. The length of the string "Hello There. " is _____.

Explanation

The length of a string is determined by the number of characters it contains. In this case, the string "Hello There. " consists of 13 characters, including the space at the end. Therefore, the correct answer is 13.

Submit
70. An array created during the execution of a program is called a(n) ____ array.

Explanation

A dynamic array is created during the execution of a program. Unlike a static array, which has a fixed size and cannot be changed once it is declared, a dynamic array can be resized and modified as needed during the program's execution. This allows for more flexibility and adaptability in handling varying amounts of data.

Submit
71. 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);

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.

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

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".

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

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.

Submit
74. The body of the main program is enclosed in parentheses.

Explanation

The body of the main program is not enclosed in parentheses. In most programming languages, the main program is typically defined by a block of code that is not enclosed in parentheses. Instead, it is usually defined by using specific keywords or symbols, such as "main()" or "public static void main(String[] args)". Therefore, the given statement is false.

Submit
75. 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;        } }

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."

Submit
76. Int j, int num = 2; int sum = 0; for (j = 1; j < = 4; j++) {        sum = sum + num; } cout << sum << endl;

Explanation

The code initializes three variables: j, num with a value of 2, and sum with a value of 0. It then enters a for loop that iterates as long as j is less than or equal to 4. In each iteration, the value of num is added to the sum. After the loop finishes, the sum is printed, which would be 8 in this case.

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

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.

Submit
78. When overloading a function, what must be true?

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.

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

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.

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

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.

Submit
81. In C++, the dot is an operator called the _____ operator.

Explanation

The dot operator in C++ is known as the member access operator. It is used to access the members (variables and functions) of a class or object. By using the dot operator, we can access and manipulate the data stored within the members of a class. Hence, the correct answer is "member access".

Submit
82. 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;                   }       }

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.

Submit
83. What is the output produced by the following segment of code?           (be sure to do the math correctly) int S = 12; int T = 5; cout << S/T <<"\t"<< S%T;

Explanation

The code segment calculates the quotient and remainder when 12 is divided by 5. The result is then printed out, with the quotient followed by a tab character and then the remainder. In this case, the quotient is 2 and the remainder is 2, so the output will be "2 2".

Submit
84. Where S is a String, the difference between cin>>S; and getline (cin, S); is that:

Explanation

The correct answer is c. getline (cin, S); allows for a multiple word entry but cin >> S; does not. This is because cin >> S; reads input until it encounters a whitespace character, while getline (cin, S); reads input until it encounters a newline character. Therefore, cin >> S; only allows for a single word entry, while getline (cin, S); allows for a multiple word entry.

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

Explanation

The correct answer is "for(j = 0; j

Submit
86. What is the output produced by the following segment of code? for (int x = 0; x <= 5; x++)             cout << "#";

Explanation



The provided C++ code outputs the character '#' six times horizontally. The loop runs six times (x takes on values 0 to 5 inclusive), and in each iteration, the '#' character is printed to the console without any spaces or newlines. Therefore, the output is "######".
Submit
87. 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; }

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."

Submit
88. Which of the following are equivalent to (!(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

Submit
89. Count = 1; num = 25; while(count < 25) {      num = num - 1;      count ++; } cout  <<  count << " "  << num << endl; What is the output of the C++ code above?

Explanation

The code initializes the variables count to 1 and num to 25. It then enters a while loop that will continue as long as count is less than 25. Inside the loop, it subtracts 1 from num and increments count by 1. After the loop, it prints the values of count and num. Since the loop runs 24 times, count becomes 25 and num becomes 1. Therefore, the output of the code is "25 1".

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

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.

Submit
View My Results

Quiz Review Timeline (Updated): Sep 1, 2024 +

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

  • Current Version
  • Sep 01, 2024
    Quiz Edited by
    ProProfs Editorial Team
  • May 11, 2011
    Quiz Created by
    Tcarteronw
Cancel
  • All
    All (90)
  • Unanswered
    Unanswered ()
  • Answered
    Answered ()
(T   F)  Another way to created a running total other...
A library is a collection of program code that can be used by other...
C++ programs should contain comments to explain the code.
(T  F)  The following symbols represent OR:  ...
What is the value of x after the following statements? ...
Which of the following is not a phase of the program-design process?
C++ is not case-sensitive.
Str1 = "abc";...
An "if" structure inside another "if" structure is called a:
(T  F) A function is invoked by a function call.
Which of the following data types may be used in a switch statement?
What is the output of the following code? ...
What is the output of the following program fragment? ...
When you type int main( ), it means that an integer will be returned.
A variable assigned int can produce a number with decimals.
An algorithm is
What is the value of x after the following code fragment executes? ...
Call-by-reference should be used
The statement num is less than 10 or num is greater than 50 in C++ is...
The following code: ...
The identifiers in the system-provided header files such as iostream,...
Assume you have the following declaration char nameList[100];. Which...
What is the output produced by the following segment of code?...
Which boolean operation is described by the following table?...
If you need to write a function that will compute the cost of some...
The expression static_cast(3) is called a
If the user types in the characters 10, and your program reads them...
It is possible when using a while loop that the body of the loop will...
A cin statement sends output to the computer screen.
Testing your program should be done
If an & is attached after the data type of a formal parameter,...
In C++, you declare a pointer variable by using the ____ symbol.
Which of the following would allow you to move to the next line:
What is wrong with the following for loop? ...
Which boolean operation is described by the following table? ...
Consider the following statement: double alpha[10][5];. The number of...
The break statement:
When a void function is called, it is known as
When a void function is called, it is known as
(T   F)  A program can still run if it has a warning...
What is the value of the following? sqrt(pow(2,4));
If x is a char variable, which of the following are legal assignment...
(T   F)  A semicolon is always placed after the...
Which of the following is not part of the Software Life Cycle?
Information Hiding is analogous to using
Cin >> num;...
// will allow you to make a multiple line comment.
What is the value returned by the following function? ...
Libraries are included after the main function.
A simplified version of a function which is used to test the main...
Cout << fixed << showpoint;...
The set of instructions that a computer will follow is known as:
Which of the following is not a valid identifier?
Cout << fixed << showpoint;...
A function that is associated with an object is called a _________...
By using a \", you can create a quotation mark inside of a string.
Suppose that alpha is a double variable. Choose the value of alpha...
Which of the following statements is NOT legal?
When parameters are passed between the calling code and the called...
X = 10;...
A variable listed in a function call is known as a(n) _____...
Which of the following is not an example of a program bug?
If a function needs to modify more than one variable, it must
A simplified main program used to test functions is called
Before using the data type string, the program must include the header...
X = 6...
X = 10;...
What is the value of x after the following statements? ...
The length of the string "Hello There. " is _____.
An array created during the execution of a program is called a(n) ____...
What is the output of the following function call? ...
When a variable is local to a function, we say that it has ___ of the...
What is the value of x after the following statement? ...
The body of the main program is enclosed in parentheses.
What is wrong with the following code? ...
Int j,...
After a stream is opened, before it is used for input and output, it...
When overloading a function, what must be true?
What is the output of the following code? ...
Given the following statements: ...
In C++, the dot is an operator called the _____ operator.
Given the following code, what is the final value of i? ...
What is the output produced by the following segment of code?...
Where S is a String, the difference between cin>>S; and getline...
Double sales [50];...
What is the output produced by the following segment of code? ...
What is the output of the following function and function call? ...
Which of the following are equivalent to (!(x<15 &&...
Count = 1;...
What is the value of x after the following statements? ...
Alert!

Advertisement