C++ Programming Multiple Choice Questions & Answers (MCQs) on “Basics”.
1. Which of the following is the correct syntax of including a user defined header files in C++?
a) #include
b) #include
c) #include “userdefined”
d) #include [userdefined]
Answer: c
Clarification: C++ uses double quotes to include a user-defined header file. The correct syntax of including user-defined is #include “userdefinedname”.
2. Which of the following is a correct identifier in C++?
a) 7var_name
b) 7VARNAME
c) VAR_1234
d) $var_name
Answer: c
Clarification: The rules for writing an identifier is as follows:
i) may contain lowercase/uppercase letters, digits or underscore(_) only
ii) should start with a non-digit character
iii) should not contain any special characters like @, $, etc.
3. Which of the following is called address operator?
a) *
b) &
c) _
d) %
Answer: b
Clarification: & operator is called address operator and is used to access the address of a variable.
4. Which of the following is used for comments in C++?
a) // comment
b) /* comment */
c) both // comment or /* comment */
d) // comment */
Answer: c
Clarification: Both the ways are used for commenting in C++ programming. // is used for single line comments and /* … */ is used for multiple line comments.
5. What are the actual parameters in C++?
a) Parameters with which functions are called
b) Parameters which are used in the definition of a function
c) Variables other than passed parameters in a function
d) Variables that are never used in the function
Answer: a
Clarification: Actual parameters are those using which a function call is made i.e. which are actually passed in a function when that function is called.
6. What are the formal parameters in C++?
a) Parameters with which functions are called
b) Parameters which are used in the definition of the function
c) Variables other than passed parameters in a function
d) Variables that are never used in the function
Answer: b
Clarification: Formal parameters are those which are used in the definition of a function. They are the parameters that represent the actual parameters passed and they are the one which is used inside the function.
7. Which function is used to read a single character from the console in C++?
a) cin.get(ch)
b) getline(ch)
c) read(ch)
d) scanf(ch)
Answer: a
Clarification: C++ provides cin.get() function to read a single character from console whereas others are used to read either a single or multiple characters.
8. Which function is used to write a single character to console in C++?
a) cout.put(ch)
b) cout.putline(ch)
c) write(ch)
d) printf(ch)
Answer: a
Clarification: C++ provides cout.put() function to write a single character to console whereas others are used to write either a single or multiple characters.
9. What are the escape sequences?
a) Set of characters that convey special meaning in a program
b) Set of characters that whose use are avoided in C++ programs
c) Set of characters that are used in the name of the main function of the program
d) Set of characters that are avoided in cout statements
