This set of C++ Programming Multiple Choice Questions & Answers (MCQs) focuses on “C++ Concepts – 1”.
1. 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
View Answer
Explanation: 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.
2. What is the size of a boolean variable in C++?
a) 1 bit
b) 1 byte
c) 4 bytes
d) 2 bytes
View Answer
Explanation: Boolean uses only 1 bit as it stores only truth values which can be true(1) or false(0).
3. Which of the following is C++ equivalent for scanf()?
a) cin
b) cout
c) print
d) input
View Answer
Explanation: C++ uses cin to read input form uses. However C++ also uses scanf().
4. Which of the following is C++ equivalent for printf()?
a) cin
b) cout
c) print
d) input
View Answer
Explanation: C++ uses cout to print output to console. However C++ also uses printf().
5. 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
View Answer
Explanation: 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.
6. Which of the following is an exit-controlled loop?
a) for
b) while
c) do-while
d) all of the mentioned
View Answer
Explanation: 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.
7. Which of the following is an entry-controlled loop?
a) for
b) while
c) do-while
d) both while and for
View Answer
Explanation: 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.
8. In which part of the for loop termination condition is checked?
for(I;II;III)
{IV}
a) I
b) II
c) III
d) IV
View Answer
Explanation: In II part the termination condition of the for loop is checked.
9. What is dynamic binding?
a) The process of linking the actual code with a procedural call during run-time
b) The process of linking the actual code with a procedural call during compile-time
c) The process of linking the actual code with a procedural call at any-time
d) All of the mentioned
View Answer
Explanation: Binding of calls and variables with actual code at run-time is called dynamic binding. For example in the concept of polymorphism types are decided are defined during the execution of code which leads to the different function calls depending upon the types used this is called dynamic binding. As the function call is decided during the run-time therefore dynamic binding happens at run-time.
10. What is static binding?
a) The process of linking the actual code with a procedural call during run-time
b) The process of linking the actual code with a procedural call during compile-time
c) The process of linking the actual code with a procedural call at any-time
d) All of the mentioned
View Answer
Explanation: Binding of calls and variables with actual code at compile-time is called static binding. For example normally whenever we declare a variable we define its type hence compiler knows what type should be binded to that variable i.e. compiler can decide about that variable this is called static binding.
11. 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
View Answer
Explanation: 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.
12. What will be the output of the following program in both C and C++?
#include<stdio.h> int main(int argc, char const *argv[]) { printf("%d\n", (int)sizeof('a')); return 0; }
a) Output in C is 1 and in C++ is 4
b) Output in C is 4 and in C++ is 1
c) Output in C is 1 and in C++ is 1
d) Output in C is 4 and in C++ is 4
View Answer
Explanation: In C a character is stored as int therefore the size of ‘a’ is printed as 4 whereas in C++ it is stored as char only therefore in C++ it prints 1.
13. What will be the output of the following C++ code?
#include<stdio.h> int main(int argc, char const *argv[]) { char a = 'a'; printf("%d\n", (int)sizeof(a)); return 0; }
a) Output in C is 1 and in C++ is 4
b) Output in C is 4 and in C++ is 1
c) Output in C is 1 and in C++ is 1
d) Output in C is 4 and in C++ is 4
View Answer
Explanation: Both in C and C++ the type char has same size which is 1. But a character enclosed inside single quotes has difference sizes i.e. in case of char a; the size of a will be 1 in both C and C++ but in case of ‘a’ size will be 4 in case of C but 1 in case of C++.
14. 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
View Answer
Explanation: 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.
15. 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++
View Answer
Explanation: 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.
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.
- Check C++ Books
- Check Computer Science Books
- Apply for Information Technology Internship
- Practice Programming MCQs
- Check Programming Books