C++ Basic MCQ Questions And Answers

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 Allcompiler
A
Allcompiler
Community Contributor
Quizzes Created: 4 | Total Attempts: 23,215
Questions: 10 | Attempts: 5,405

SettingsSettingsSettings
C++ Basic MCQ Questions And Answers - Quiz

Get ready for these C++ basic MCQ questions and answers. This quiz is created for those users who want to test their command over the C++ Programming Language. The quiz is gonna be helpful to learn even more about C++ in a fun way. You will be called an expert in this subject if you manage to get more than 70 on this quiz. So, are you ready and excited? Let's go for it!



Questions and Answers
  • 1. 

    A variable is/are

    • A.

      A string that varies during program execution

    • B.

      A portion of memory to store a determined value

    • C.

      Those numbers that are frequently required in programs

    • D.

      None of these

    Correct Answer
    B. A portion of memory to store a determined value
    Explanation
    The correct answer is "A portion of memory to store a determined value". In programming, a variable is a named location in memory that holds a value. It is used to store and manipulate data during program execution. Variables can hold different types of values such as numbers, strings, or boolean values, and their values can change throughout the program. They provide a way to store and access data efficiently, making it easier to work with and manipulate information in a program.

    Rate this question:

  • 2. 

    Which of the following cannot be used as identifiers?

    • A.

      Letters

    • B.

      Digits

    • C.

      Underscores

    • D.

      Spaces

    Correct Answer
    D. Spaces
    Explanation
    Spaces cannot be used as identifiers because in most programming languages, identifiers are used to represent variables, functions, or other entities in the code. Spaces are not allowed because they can cause ambiguity and confusion in the code. Instead, developers typically use underscores or camel case to separate words within an identifier.

    Rate this question:

  • 3. 

    Which of the following identifiers is invalid?

    • A.

      Papername

    • B.

      Writername

    • C.

      Typename

    • D.

      Printname

    Correct Answer
    C. Typename
    Explanation
    The identifier "Typename" is invalid because it starts with an uppercase letter, which is not allowed in most programming languages. Identifiers usually start with a lowercase letter or an underscore.

    Rate this question:

  • 4. 

    Which of the following cannot be used as a valid identifier?

    • A.

      Bitand

    • B.

      Bittand

    • C.

      Biand

    • D.

      Band

    Correct Answer
    A. Bitand
    Explanation
    The identifier "bitand" cannot be used as a valid identifier because it is a reserved keyword in many programming languages, including C++, C#, and Java. Reserved keywords have a predefined meaning in the language and cannot be used as identifiers for variables, functions, or other elements in the code. Using "bitand" as an identifier would result in a syntax error.

    Rate this question:

  • 5. 

    The difference between x and ‘x’ is

    • A.

      The first one refers to a variable whose identifier is x and the second one refers to the character constant x

    • B.

      The first one is a character constant x, and second one is the literal string x

    • C.

      Both are same

    • D.

      None of above

    Correct Answer
    A. The first one refers to a variable whose identifier is x and the second one refers to the character constant x
    Explanation
    The correct answer is that the first one refers to a variable whose identifier is x and the second one refers to the character constant x. This means that the first one is a variable that can hold a value, while the second one is a specific character constant.

    Rate this question:

  • 6. 

    Which of the following is not a valid escape code?

    • A.

      \t

    • B.

      \v

    • C.

      \f

    • D.

      \w

    Correct Answer
    D. \w
  • 7. 

    Which of the following statement is true?

    • A.

      String Literals can extend to more than a single line of code by putting a backslash sign at the end of each unfinished line.

    • B.

      You can also concatenate several string constants, separating them by one or several blank spaces, tabulators, newlines, or any other valid blank character.

    • C.

      If we want the string literal to explicitly made of wide characters, we can precede the constant with the L prefix.

    • D.

      All of above

    Correct Answer
    D. All of above
    Explanation
    All of the statements given are true. String literals can extend to more than a single line of code by using a backslash at the end of each unfinished line. Multiple string constants can be concatenated by separating them with blank spaces, tabulators, newlines, or any other valid blank character. If we want the string literal to be explicitly made of wide characters, we can use the L prefix. Therefore, the correct answer is "All of above."

    Rate this question:

  • 8. 

    Regarding #difine, which of the following statement is false?

    • A.

      It is not a C++ statement but the directive for the preprocessor.

    • B.

      This does not require a semicolon at the end of line.

    • C.

      It is a C++ statement that declares a constant in C++.

    • D.

      None of the above

    Correct Answer
    C. It is a C++ statement that declares a constant in C++.
    Explanation
    The statement "It is a C++ statement that declares a constant in C++" is false. The correct answer is that #define is not a C++ statement but the directive for the preprocessor. #define is used to define constants or macros in C++ and is processed by the preprocessor before the actual compilation of the code. It does not require a semicolon at the end of the line.

    Rate this question:

  • 9. 

    Regarding the following statement, which of the statements is true? const int pathwidth=100;

    • A.

      Declares a variable pathwidth with 100 as its initial value

    • B.

      Declares a construction pathwidth with 100 as its initial value

    • C.

      Declares a constant pathwidth whose value will be 100

    • D.

      Constructs an integer type variable with pathwidth as identifier and 100 as value

    Correct Answer
    C. Declares a constant pathwidth whose value will be 100
    Explanation
    The given statement "const int pathwidth=100;" declares a constant variable named pathwidth with an initial value of 100.

    Rate this question:

  • 10. 

    In an assignment statement

    • A.

      The value must always be a variable.

    • B.

      The value might be a constant, a variable, an expression, or any combination of these.

    • C.

      The assignment always takes place from right to left and never the other way.

    • D.

      All of above

    Correct Answer
    D. All of above
    Explanation
    The correct answer is "All of above". This is because in an assignment statement, the value can be a constant, a variable, an expression, or any combination of these. The assignment always takes place from right to left and never the other way. Therefore, all the statements mentioned in the options are correct.

    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
  • Apr 21, 2023
    Quiz Edited by
    ProProfs Editorial Team
  • Sep 15, 2011
    Quiz Created by
    Allcompiler
Back to Top Back to top
Advertisement
×

Wait!
Here's an interesting quiz for you.

We have other quizzes matching your interest.