Test Series - cpp

Test Number 6/102

Q: Which of the following is not a fundamental type is not present in C but present in C++?
A. int
B. float
C. bool
D. void
Solution: Boolean type is not present as a fundamental type in C. int type is used as boolean in C whereas in C++ bool is defined as a fundamental type for handling boolean outputs.
Q: What is the size of a boolean variable in C++?
A. 1 bit
B. 1 byte
C. 4 bytes
D. 2 bytes
Solution: Boolean uses only 1 bit as it stores only truth values which can be true(1) or false(0).
Q: Which of the following is C++ equivalent for scanf()?
A. cin
B. cout
C. print
D. input
Solution: C++ uses cin to read input form uses. However C++ also uses scanf().
Q: Which of the following is C++ equivalent for printf()?
A. cin
B. cout
C. print
D. input
Solution: C++ uses cout to print output to console. However C++ also uses printf().
Q: Which of the following is the correct difference between cin and scanf()?
A. both are the same
B. cin is a stream object whereas scanf() is a function
C. scanf() is a stream object whereas cin is a function
D. cin is used for printing whereas scanf() is used for reading input
Solution: cin is a stream object available in C++ whereas scanf() is a function available in both C and C++. both are used for reading input from users.
Q: Which of the following is an exit-controlled loop?
A. for
B. while
C. do-while
D. all of the mentioned
Solution: do-while is called exit controlled loop because in do-while termination condition is checked when we have executed the body of the loop i.e. we are exiting the body and then checking the condition, therefore, it is called exit controlled loop.
Q: Which of the following is an entry-controlled loop?
A. for
B. while
C. do-while
D. both while and for
Solution: Both while and for loops are called entry controlled loop because in both of them the termination condition is checked before we enter the body of the loop hence they are called entry controlled loop.
Q: What is name mangling in C++?
A. The process of adding more information to a function name so that it can be distinguished from other functions by the compiler
B. The process of making common names for all the function of C++ program for better use
C. The process of changing the names of variable
D. The process of declaring variables of different types
Solution: Name mangling is the process of adding some more information to a function name so that it can be distinguished from other functions by the compiler. This is used when a programmer uses the concept of function overloading in his/her program.
Q: Which of the following syntax for declaring a variable of struct STRUCT can be used in both C and C++?
A. struct STRUCT S;
B. STRUCT S;
C. Both struct STRUCT S; and STRUCT S;
D. Both C and C++ have different syntax
Solution: C program requires struct keyword while defining a variable of any structure, therefore, we cannot use the second STRUCT S; definition to declare a variable.
Q: What if we define the below structure in C and C++?
A. Error in C but not in C++
B. Error in C++ but not in C
C. No error in both C and C++
D. Error in both C and C++
Solution: The above definition will give an error in C but not in C++ as C does not allows the programmer to give any default values to any member of structure but C++ does allow.

You Have Score    /10