C++ Programming Questions and Answers – Basics

This set of C++ Programming Multiple Choice Questions & Answers (MCQs) focuses on “Basics”.

1. Which of the following is the correct syntax of including a user defined header files in C++?
a) #include <userdefined.h>
b) #include <userdefined>
c) #include “userdefined”
d) #include [userdefined]
View Answer

Answer: c
Explanation: 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
View Answer

Answer: c
Explanation: 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) %
View Answer

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

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

Answer: c
Explanation: 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
View Answer

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.
Sanfoundry Certification Contest of the Month is Live. 100+ Subjects. Participate Now!

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
View Answer

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.

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)
View Answer

Answer: a
Explanation: C++ provides cin.get() function to read a single character from console whereas others are used to read either a single or multiple characters.
advertisement

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)
View Answer

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

Answer: a
Explanation: Escape sequence is a set of characters that convey a special meaning to the program. They are used to convey a meaning which cannot be conveyed directly.
advertisement

10. Which of the following escape sequence represents carriage return?
a) \r
b) \n
c) \n\r
d) \c
View Answer

Answer: a
Explanation: \r is used to represent carriage return which means move the cursor to the beginning of the next line.

11. Which of the following escape sequence represents tab?
a) \t
b) \t\r
c) \b
d) \a
View Answer

Answer: a
Explanation: \t is used to represent tab which means a set of blank spaces in a line.

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

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

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

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

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

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

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

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

Sanfoundry Global Education & Learning Series – C++ Programming Language.

To practice all areas of C++ language, here is complete set of 1000+ Multiple Choice Questions and Answers.

If you find a mistake in question / option / answer, kindly take a screenshot and email to [email protected]

advertisement
advertisement
Subscribe to our Newsletters (Subject-wise). Participate in the Sanfoundry Certification contest to get free Certificate of Merit. Join our social networks below and stay updated with latest contests, videos, internships and jobs!

Youtube | Telegram | LinkedIn | Instagram | Facebook | Twitter | Pinterest
Manish Bhojasia - Founder & CTO at Sanfoundry
Manish Bhojasia, a technology veteran with 20+ years @ Cisco & Wipro, is Founder and CTO at Sanfoundry. He lives in Bangalore, and focuses on development of Linux Kernel, SAN Technologies, Advanced C, Data Structures & Alogrithms. Stay connected with him at LinkedIn.

Subscribe to his free Masterclasses at Youtube & discussions at Telegram SanfoundryClasses.