Trivia Quiz: Could You Really Pass This C++ Test?

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 Bnath
B
Bnath
Community Contributor
Quizzes Created: 1 | Total Attempts: 132
Questions: 36 | Attempts: 132

SettingsSettingsSettings
Trivia Quiz: Could You Really Pass This C++ Test? - Quiz

Could you really pass this C++ test? Do you think you know everything about the language? Well you are in luck as the quiz below perfect for you, and it has combined some questions from past certification exams, and if you are able to get even three-quarters of the mark, you have nothing to worry about when it comes to the finals. Give it a try!


Questions and Answers
  • 1. 

    What is the correct value to return to the operating system upon the successful completion of a program?   A. -1  B. 1  C. 0  D. Programs do not return a value.

    Explanation
    Upon the successful completion of a program, the correct value to return to the operating system is 0. This is a widely accepted convention in programming. Returning 0 signifies that the program executed without any errors or issues. Other values like -1 or 1 may be used to indicate specific error conditions or abnormal terminations, but for a successful completion, 0 is the appropriate value to return.

    Rate this question:

  • 2. 

     What is the only function all C programs must contain? A. start() B. system()  C. main()  D. program()

    Explanation
    The correct answer is C. In C programming, every program must contain a main() function. This function serves as the starting point of execution for the program. It is where the program begins its execution and where the program terminates. The main() function can also accept command line arguments and return an integer value to indicate the status of the program's execution. Therefore, all C programs must have a main() function.

    Rate this question:

  • 3. 

     What punctuation is used to signal the beginning and end of code blocks? A. { }  B. -> and <-  C. BEGIN and END  D. ( and ) 

    Explanation
    The punctuation { } is commonly used in programming languages to enclose and define the beginning and end of code blocks. This punctuation is often referred to as curly braces or brackets. It is used to group together multiple statements or lines of code, indicating that they are part of the same block and should be executed together. The opening curly brace { signals the start of the code block, while the closing curly brace } indicates the end of the block.

    Rate this question:

  • 4. 

     What punctuation ends most lines of C code? A. .  B. ;  C. :  D. ' 

    Explanation
    Most lines of C code end with a semicolon (;). This is because in C, the semicolon is used to indicate the end of a statement. Without a semicolon, the code would not compile correctly and would result in a syntax error. Therefore, option B is the correct answer.

    Rate this question:

  • 5. 

     Which of the following is a correct comment? A. */ Comments */ B. ** Comment ** C. /* Comment */ D. { Comment }

    Explanation
    The correct comment is C because it follows the syntax of a multi-line comment in many programming languages, such as C, C++, and Java. The /* at the beginning and the */ at the end indicate that everything in between is a comment and will be ignored by the compiler or interpreter.

    Rate this question:

  • 6. 

     Which of the following is not a correct variable type? A. float B. real C. int D. double

    Explanation
    The variable type "real" is not a correct variable type. In programming languages, commonly used variable types include float, int, and double for representing numbers. However, "real" is not a standard variable type in most programming languages.

    Rate this question:

  • 7. 

    Which of the following is the correct operator to compare two variables? A. := B. = C. equal D. ==

    Explanation
    The correct operator to compare two variables is "==". This operator checks if the values of the two variables are equal and returns a boolean value of either true or false. The other options, ":=", "=", and "equal", are not valid comparison operators in most programming languages.

    Rate this question:

  • 8. 

     Which of the following is the boolean operator for logical-and? A. & B. && C. | D. |&

    Explanation
    The correct answer is B. The boolean operator for logical-and is &&. This operator returns true if both operands are true, and false otherwise. The symbol & is a bitwise operator, not a logical operator. The symbol | is the boolean operator for logical-or, and the symbol |& is not a valid boolean operator.

    Rate this question:

  • 9. 

     Evaluate !(1 && !(0 || 1)). A. True B. False C. Unevaluatable

    Explanation
    The expression !(1 && !(0 || 1)) can be evaluated as follows:
    First, inside the parentheses, the logical OR operator || evaluates to true because at least one of the operands (0 and 1) is true.
    Next, the logical NOT operator ! negates the result of the logical OR operator, resulting in false.
    Finally, the logical AND operator && compares the value 1 with the negated result false, which evaluates to false.
    Therefore, the overall expression evaluates to true.

    Rate this question:

  • 10. 

    Which of the following shows the correct syntax for an if statement? A. if expression B. if { expression C. if ( expression ) D. expression if

    Explanation
    The correct answer is C. The if statement in programming is used to perform a certain action if a specified condition is true. In order to write an if statement, the condition needs to be enclosed in parentheses. Therefore, option C, "if ( expression )", shows the correct syntax for an if statement.

    Rate this question:

  • 11. 

    What is the final value of x when the code int x; for(x=0; x<10; x++) {} is run? A. 10 B. 9 C. 0 D. 1

    Explanation
    Note: This quiz question probably generates more doubt. Yes, the answer really is 10. If you don't understand why, think about it this way: what condition has to be true for the loop to stop running?

    Rate this question:

  • 12. 

    When does the code block following while(x<100) execute? A. When x is less than one hundred B. When x is greater than one hundred C. When x is equal to one hundred D. While it wishes

    Explanation
    The code block following the while(x

    Rate this question:

  • 13. 

    Which is not a loop structure? A. For B. Do while C. While D. Repeat Until

    Explanation
    The correct answer is D. The reason why D is not a loop structure is because "Repeat Until" is not a commonly used loop structure in programming languages. The other options, A, B, and C (For, Do while, While) are all commonly used loop structures in programming languages.

    Rate this question:

  • 14. 

    How many times is a do-while loop guaranteed to loop? A. 0 B. Infinitely C. 1 D. Variable

    Explanation
    A do-while loop is guaranteed to loop at least once because the condition is checked at the end of the loop. This means that the loop will always execute the code block once before checking the condition. Therefore, the correct answer is C, which indicates that a do-while loop is guaranteed to loop 1 time.

    Rate this question:

  • 15. 

    Which is not a proper prototype? A. int funct(char x, char y); B. double funct(char x) C. void funct(); D. char x();

    Explanation
    The prototype "double funct(char x)" is not proper because it does not specify the return type of the function. In C/C++, every function prototype should include the return type, even if it is void. Therefore, option B is not a proper prototype.

    Rate this question:

  • 16. 

    What is the return type of the function with prototype: "int func(char x, float v, double t);" A. char B. int C. float D. double

    Explanation
    The return type of the function with the given prototype "int func(char x, float v, double t);" is int. This is because the return type is specified before the function name, and in this case, it is int. The function is expected to return a value of type int.

    Rate this question:

  • 17. 

     Which of the following is a valid function call (assuming the function exists)? A. funct; B. funct x, y; C. funct(); D. int funct();

    Explanation
    The correct answer is C. This is a valid function call because it includes the parentheses after the function name, indicating that the function is being called with no arguments.

    Rate this question:

  • 18. 

     Which of the following is a complete function? A. int funct(); B. int funct(int x) {return x=x+1;} C. void funct(int) { printf( "Hello");  D. void funct(x) { printf( "Hello"); }

    Explanation
    The correct answer is B. This is because function B has a return type of int, takes an integer parameter x, and returns the value of x+1. It is a complete function because it has a defined return type, parameter, and body.

    Rate this question:

  • 19. 

    Which follows the case statement? A. : B. ; C. - D. A newline

    Explanation
    The correct answer is A because in most programming languages, a colon (:) is used to introduce a case statement. It is used to separate the condition from the block of code that will be executed if the condition is true.

    Rate this question:

  • 20. 

    What is required to avoid falling through from one case to the next? A. end; B. break; C. Stop; D. A semicolon.

    Explanation
    To avoid falling through from one case to the next, the keyword "break" is required. The "break" statement is used in switch statements to terminate the current case and exit the switch block. It prevents the execution of the subsequent cases and ensures that only the code associated with the matching case is executed. The other options, "end;", "Stop;", and "A semicolon" are not valid keywords or statements for this purpose.

    Rate this question:

  • 21. 

     What keyword covers unhandled possibilities? A. all B. contingency C. default D. other

    Explanation
    The keyword "default" covers unhandled possibilities. This means that if none of the specified cases in a switch statement match the given condition, the default case will be executed. It acts as a fallback option for any unhandled possibilities.

    Rate this question:

  • 22. 

    What is the result of the following code? int x=0;   switch(x)   {     case 1: printf( "One" );     case 0: printf( "Zero" );     case 2: printf( "Hello World" );   }
    • A. One
    • B. Zero
    • C. Hello World
    • D. ZeroHello World

    Explanation
    The code uses a switch statement to check the value of the variable x. Since x is initialized to 0, the case 0 is matched. However, there are no break statements after each case, so the code continues to execute the following cases. As a result, both case 0 and case 2 are executed. Therefore, the output will be "ZeroHello World".

    Rate this question:

  • 23. 

     Which of the following accesses a variable in structure b? A. b->var; B. b.var; C. b-var; D. b>var;

    Explanation
    The correct answer is B because it uses the dot operator to access a variable in the structure b. The dot operator is used to access members of a structure using the structure variable name followed by the dot operator and the member name. In this case, b.var accesses the variable var in the structure b.

    Rate this question:

  • 24. 

    Which of the following accesses a variable in structure *b? A. b->var; B. b.var; C. b-var; D. b>var;

    Explanation
    The correct answer is A. This is because the arrow operator "->" is used to access a member variable in a structure pointer. In this case, the structure pointer is "*b" and the member variable is "var". Therefore, "b->var" correctly accesses the variable in structure *b.

    Rate this question:

  • 25. 

    Which of the following is a properly defined struct? A. struct {int a;} B. struct a_struct {int a;} C. struct a_struct int a; D. struct a_struct {int a;};

    Explanation
    Option D is the correct answer because it properly defines a struct named "a_struct" with a member variable "a" of type int. The struct definition is enclosed within curly braces and terminated with a semicolon, which is the correct syntax for defining a struct in C or C++. Option A is incorrect because it is missing the name of the struct. Option B is correct in terms of syntax, but it does not follow the convention of starting struct names with a lowercase letter. Option C is incorrect because it incorrectly places the type specifier "int" after the struct definition.

    Rate this question:

  • 26. 

    Which properly declares a variable of struct foo? A. struct foo; B. struct foo var; C. foo; D. int foo;

    Explanation
    The correct answer is B. This is because in order to declare a variable of struct foo, we need to use the "struct" keyword followed by the name of the struct (foo) and then the variable name (var). Option A only declares the struct foo itself, not a variable of it. Option C is incorrect because it does not include the "struct" keyword. Option D declares a variable of type int, not struct foo.

    Rate this question:

  • 27. 

     Which of the following correctly declares an array? A. int anarray[10]; B. int anarray; C. anarray{10}; D. array anarray[10];

    Explanation
    Option A correctly declares an array named "anarray" of type int with a size of 10. The square brackets [] indicate that it is an array, and the number inside the brackets specifies the size of the array.

    Rate this question:

  • 28. 

    What is the index number of the last element of an array with 29 elements? A. 29 B. 28 C. 0 D. Programmer-defined

    Explanation
    The index number of the last element in an array is always one less than the total number of elements in the array. Since the array in this question has 29 elements, the index number of the last element would be 28. Therefore, option B is the correct answer.

    Rate this question:

  • 29. 

    Which of the following is a two-dimensional array? A. array anarray[20][20]; B. int anarray[20][20]; C. int array[20, 20]; D. char array[20];

    Explanation
    The correct answer is B because it declares a two-dimensional array named "anarray" of type int with dimensions 20x20. The syntax of declaring a two-dimensional array is "datatype arrayname[row_size][column_size]". Option A also declares a two-dimensional array, but it doesn't specify the data type. Option C uses the incorrect syntax for declaring a two-dimensional array. Option D declares a one-dimensional array of type char.

    Rate this question:

  • 30. 

    Which of the following correctly accesses the seventh element stored in foo, an array with 100 elements? A. foo[6]; B. foo[7]; C. foo(7); D. foo;

    Explanation
    The correct answer is A because arrays in most programming languages are zero-indexed, meaning the first element is accessed using the index 0. Since the question asks for the seventh element, which is at index 6, the correct way to access it is foo[6].

    Rate this question:

  • 31. 

    Which of the following gives the memory address of the first element in array foo, an array with 100 elements? A. foo[0]; B. foo; C. &foo; D. foo[1];

    Explanation
    The correct answer is B. In C++, the name of an array is a pointer to its first element. Therefore, "foo" gives the memory address of the first element in the array.

    Rate this question:

  • 32. 

    Which of the following is a static string? A. Static String B. "Static String" C. 'Static String' D. char string[100];

    Explanation
    The correct answer is B because it is enclosed in double quotation marks, which is the standard way to represent a static string in most programming languages. Option A is not a static string because it is missing the quotation marks. Option C is not a static string because it uses single quotation marks, which typically represent a single character rather than a string. Option D is not a static string because it is an array of characters rather than a string itself.

    Rate this question:

  • 33. 

    What character ends all strings? A. '.' B. ' ' C. '\0' D. '\n'

    Explanation
    The character that ends all strings is the null character, represented as '\0'. This character is used to indicate the end of a string in many programming languages, including C and C++. It is placed at the end of a string to mark the termination point and ensure that the string is properly terminated.

    Rate this question:

  • 34. 

    Which of the following reads in a string named x with one hundred characters? A. fgets(x, 101, stdin); B. fgets(x, 100, stdin); C. readline(x, 100, '\n'); D. read(x);

    Explanation
    The correct answer is A. The fgets() function reads a string from the input stream (in this case, stdin) and stores it in the variable x. The second argument specifies the maximum number of characters to read, which in this case is 101 to accommodate for the null terminator. Therefore, option A correctly reads in a string named x with one hundred characters.

    Rate this question:

  • 35. 

     Which of the following functions compares two strings? A. compare(); B. stringcompare(); C. cmp(); D. strcmp();

    Explanation
    The correct answer is D. The strcmp() function compares two strings.

    Rate this question:

  • 36. 

     Which of the following adds one string to the end of another? A. append(); B. stringadd(); C. strcat(); D. stradd();

    Explanation
    The correct answer is C. strcat(). The strcat() function is used in C programming language to concatenate (append) one string to the end of another string. It takes two arguments - the destination string and the source string, and appends the source string to the end of the destination string.

    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 17, 2023
    Quiz Edited by
    ProProfs Editorial Team
  • Sep 20, 2011
    Quiz Created by
    Bnath
Advertisement
×

Wait!
Here's an interesting quiz for you.

We have other quizzes matching your interest.