C++ Questions and Answers Part-1

1. Who created C++?
a) Ken Thompson
b) Bjarne Stroustrup
c) Dennis Ritchie
d) Brian Kernighan

Answer: b
Explanation: Bjarne Stroustrup is the original creator of C++ during 1979 at AT & T Bell Labs.

2. Which of the following is called extraction/get from operator?
a) <
b) >
c) <<
d) >>

Answer: d
Explanation: >> operator is called extraction or get from operator i.e. extract/get things from console/files.

3. 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 that are never used in the function
d) Variables other than passed parameters in a function

Answer: b
Explanation: 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.

4. Which of the following is a correct identifier in C++?
a) 7var_name
b) $var_name
c) VAR_1234
d) 7VARNAME

Answer: c
Explanation: The rules for writing an identifier is :
1) may contain lowercase/uppercase letters, digits or underscore(_) only
2) should start with a non-digit character
3) should not contain any special characters like @, $, etc

5. Which of the following is called insertion/put to operator?
a) <
b) >
c) <<
d) >>

Answer: c
Explanation: << operator is called insertion or put to operator i.e. insert/put things to console/files.

6. Which of the following is used for comments in C++?
a) /* comment */
b) // comment
c) // comment */
d) both // comment or /* comment */

Answer: d
Explanation: Both the ways are used for commenting in C++ programming. // is used for single line comments and /* … */ is used for multiple line comments.

7. 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 that are never used in the function
d) Variables other than passed parameters in a function

Answer: a
Explanation: 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.

8. How structures and classes in C++ differ?
a) In Structures, members are public by default whereas, in Classes, they are private by default
b) Structures by default hide every member whereas classes do not
c) Structures cannot have private members whereas classes can have
d) In Structures, members are private by default whereas, in Classes, they are public by default

Answer: a
Explanation: Structure members are public by default whereas class members are private by default. Both of them can have private and public members.

9. A language which has the capability to generate new data types are called ________________
a) Overloaded
b) Extensible
c) Reprehensible
d) Encapsulated

Answer: b
Explanation: Languages that can produce/generate new data types are called extensible languages as they have the ability to handle new data types.

10. Which of the following is called address operator?
a) %
b) *
c) _
d) &

Answer: d
Explanation: & operator is called address operator and is used to access the address of a variable.