Test Series - cpp

Test Number 1/102

Q: 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]
Solution: C++ uses double quotes to include a user-defined header file. The correct syntax of including user-defined is #include “userdefinedname”.
Q: Which of the following is a correct identifier in C++?
A. 7var_name
B. 7VARNAME
C. VAR_1234
D. $var_name
Solution: 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.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.
Q: Which of the following is called address operator?
A. *
B. &
C. _
D. %
Solution: & operator is called address operator and is used to access the address of a variable.
Q: Which of the following is used for comments in C++?
A. // comment
B. /* comment */
C. both // comment or /* comment */
D. // comment */
Solution: Both the ways are used for commenting in C++ programming. // is used for single line comments and /* … */ is used for multiple line comments.
Q: 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
Solution: 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.
Q: 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
Solution: 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.
Q: 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)
Solution: C++ provides cin.get() function to read a single character from console whereas others are used to read either a single or multiple characters.
Q: 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)
Solution:  C++ provides cout.put() function to write a single character to console whereas others are used to write either a single or multiple characters.
Q: 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
Solution: 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.
Q: Which of the following escape sequence represents carriage return?
A. 
B. 
C. 
D. c
Solution: 
 is used to represent carriage return which means move the cursor to the beginning of the next line.

You Have Score    /10