C++ Multiple Choice QuestionsMCQ Based on Basics of C++1) #include<userdefined.h> Which of the following is the correct syntax to add the header file in the C++ program?
Answer: D Explanation: To include the herder files in the C++ program user can use any of the following given syntax. Or 2) Which of the following is the correct syntax to print the message in C++ language?
Answer: A Explanation: To print the message in the C++ language user can use the following syntax: 3) Which of the following is the correct identifier?
Answer: B Explanation: There are some certain rules that must be followed by the users while writing the identifiers.
4) Which of the following is the address operator?
Answer: C Explanation: To print the address of any variable, a user can use the "&" operator. To understand it more clearly, consider the following example: 5) Which of the following features must be supported by any programming language to become a pure object-oriented programming language?
Answer: D Explanation: There is nothing that forces a user to use the OOP concept in C++. In contrast, it is necessary for a programming language that it must support all three features as encapsulation, inheritance, and polymorphism completely to become a pure Object-Oriented Language. 6) The programming language that has the ability to create new data types is called___.
Answer: D Explanation: A language that can generate the new data types is known as the extensible languages as they can handle the new data types. 7) Which of the following is the original creator of the C++ language?
Answer: C Explanation: Bjarne Stroustrup creates C++ language during 1997 at AT&T Bell Labs. 8) Which of the following is the correct syntax to read the single character to console in the C++ language?
Answer: C Explanation: The "cin.get()" is one of the several functions provided in C++ language that is used to read the single or multiple characters to console. 9) Which of the following statements is correct about the formal parameters in C++?
Answer: A Explanation: Parameters that are used in the body of the function are known as formal parameters. These parameters represent the parameters passed to the function and are only used inside the function's body. 10) The C++ language is ______ object-oriented language.
Answer: C Explanation: The common thing about the Pure Object-oriented language it provides three basic features like Inheritance, Encapsulation, and Polymorphism. Each programming language that supports these entire three features is known as the Pure-Object oriented language. Whereas if a programming language support all these three features but not support completely are known as the Partial-Object oriented languages or the Semi Object-oriented languages The main reasons why the C++ programming language is Known as Semi-Object oriented language are as follows:
11) Which of the following features is required to be supported by the programming language to become a pure object-oriented programming language?
Answer: D Explanation: There is nothing that forces a user to use the OOP concept in C++. In contrast, it is necessary for a programming language that it must support all three features of Encapsulation, Inheritance, and Polymorphism completely to become a Pure Object-Oriented Language. 12) Which of the following comment syntax is correct to create a single-line comment in the C++ program?
Answer: A Explanation: To create a single line comment (or one-line comment) in C++ program one can use the "// write comment" syntax. We can understand it more easily with the help of following given Program: Example Output Welcome to Javatpoint 13) C++ is a ___ type of language.
Answer: C Explanation: C++ contains the features of both types of high and Low-level programming languages, and it is also not wrong if we call it the combination of both high and low-level languages. 14) For inserting a new line in C++ program, which one of the following statements can be used?
Answer: A Explanation: To insert a new line or to jump on to the next line, one can use the "\n." In c++, there is also an alternative is available that is " endl," which is also used for breaking a line in the output. Let see the example of both the "\n" and "endl." Example: Using "\n." Output Hello World! I am learning C++ Example: With using "end" Output Hello World! I am learning C++ 15) Which one of the following represents the tab?
Answer: B Explanation: The "\t" is a type of space sequence representing the tab, which means a set of blank space adds to the line. To understand it more clearly, consider the following example: Program Output Enter the first number 12 Enter the second number 13 Greatest number is 13 Set of MCQ Based on Arrays of the C++1) Which of the following refers to characteristics of an array?
Answer: A Explanation: Basically, an array is a set of similar data items that are stored in the contiguous memory blocks. You can access any data item randomly using the index address of the element s. 2) If we stored five elements or data items in an array, what will be the index address or the index number of the array's last data item?
Answer: C Explanation: The array uses the contiguous block of memory for storing the data elements. Hence the data items pushed into an array are stored at the continuous address space. The index number of the array begins with zero so, the first data item pushed into the array will be stored at zero and so on. Hence index number of the last (fifth) element will be 4. 3) Which of the following is the correct syntax for declaring the array?
Answer: B Explanation: To declare an array in C++, we first need to specify its data type according to requirements such as int or char, afterward that the array's name and the size of the array. So the correct answer will be B. Example: Array declaration by specifying size and initializing elements int arr[8] = { 10, 20, 30, 40 }; The compiler will create an array of size 8, initializes the first four elements as specified by the user and rest elements as 0 The above is just same as "int arr[] = {11, 22, 32, 44, 0, 0,0,0}". 4) Which of the following is the correct syntax for printing the address of the first element?
Answer: A Explanation: To print or access the first data item of the array, the correct syntax is "array[0];" because the array's index begins with zero instead of one. So the correct answer will be A. 5) Which of the following gives the 4th element of the array?
Answer: C Explanation: The index of the array begins with zero instead of 1. To print the 4th element of the array, the index number will be n-1 or (3); 6) What is the output of the given program?
Answer: B Explanation: It will print the negative value of the specified values because the "-" sign we used while specifying the array elements. So the correct answer will be the "-30". 7) Which type of memory is used by an Array in C++ programming language?
Answer: A Explanation: In the C and C++ programming language, the memory used by an array is usually contiguous, which means when an array is declared or initialized in the program a block of memory is selected form the memory space immediately. The major drawback of an array is that users have to guess the size of the array before actually using it, in which a significant amount of memory will be occupied even when it is not used. This later creates the problem of lack of memory. 8) Which of the following is the correct definition of sorting?
Answer: A Explanation: Sorting is a type of technique or process in which the locations of data elements hold by the array are reordered or manipulated. So the correct answer will be A. For Example Un-sorted Array
Sorted Array
9) How many types of the array are there in the C++ programming language?
Answer: C Explanation: In the C++ programming language, there are mainly two types of arrays that are Single Dimension arrays and Multi-Dimension arrays. In Single-Dimension arrays, the same types of values are hold in the form of a List, while on the other hand, in Multi-Dimension arrays; values are stored in the form of a matrix. 10) In C++, for what purpose the "rank()" is used?
Answer: C Explanation: In C++, one can use the rank function where he wants to know about the dimensions( e.g., single-dimension, multi-dimension) of a specific array by just passing it to the "rank()" function. 11) Which one of the following is the correct definition of the "is_array();" function in C++?
Answer: A Explanation: In C++, the "is_array();" is used for checking that the specified element or data item belongs to the array type or not. 12) Observer the given C++ program carefully and choose the correct output from the given options: Program
Answer: C Explanation: The correct output will be "010" Because in both cases, A and C variables passed to the "is_array()" function are different, so the function returns zero in both cases while in the case of B, they are the same. Hence it returns one as the output. 13) Read the given C++ program carefully and choose the correct output from the given options: Program
Answer: C Explanation: As we can see in the above program, here, the "rank()" function is used. The "rank()" function is used to know about the dimensions of the passed array. In case A the array passed to the "rank()" function is single-dimensional, In case B, the passed array is 2-dimensional, and in case C, the array passed is three-dimensional. So the output return by the "rank()" function is 123. 14) What did we call an array of the one-dimensional array?
Answer: C Explanation: An array of one-dimensional array is known as the 2-dimensional array or 2D Array-like Initialization of 2-Dimensional Array 15) Which types of arrays are always considered as linear arrays?
Answer: A Explanation: Single-dimensional arrays are always considered as linear arrays. 16) Which of the following can be considered as the object of an array?
Answer: B Explanation: The elements in the array are known as the objects of the array. 17) How many types of elements can an array store?
Answer: A Explanation: An array can hold several elements except that all the data elements are of the same type. 18) Elements of a one-dimensional array are numbered as 0,1,2,3,4,5, and so on; these numbers are known as ____
Answer: D Explanation: The elements of one-dimensional array are indexed as 0,1,2,3,... and these numbers are also known as the index values or subscripts of the array. MCQ Based on the Oops Concepts of the C++1) Which of the following statement is true about the new and malloc? I. The "new" is a type of operator while "malloc" is a kind of function
Answer: C Explanation: All statements mentioned in the above question are completely true about the "malloc" and the "new." The "malloc" is a kind of function available in the C++ language, while the "new" is a type of operator that invokes the Constructor. 2) Which of the following statement is true about the new and malloc? I. The pointer object initialization of a specific class using "malloc" also needs to include constructor calls; on the other hand, doing so with the "new" keyword does not include any constructor calls.
Answer: A Explanation: In object initialization of a class using the "new" keyword also involves a constructor call, while doing so with the "malloc" does not require any involvement of the constructor call. This is the main reason why the "new" is added explicitly in the C++ language. However, the "malloc" function is used to assign the memory to any specific pointer, so it assigns an equal amount of memory to the class size. At the same time, the "new" keyword involves the initialization, hence invokes the Constructor of that particular class. 3) Which of the following statement is correct about Virtual Inheritance?
Answer: D Explanation: 4) Which one of the following statements correctly refers to the Delete and Delete[] in C++ programming language?
Answer: D Explanation: The "Delete" is used with the single general object, while on the other hand, the "Delete[]" is used with the array of the multiple objects initiated with the new operator. 5) Consider the following given program and choose the most appropriate output from the given options:
Answer: D Explanation: As mentioned in the above-given program, five-pointer variables are initiated using the "new" keyword so that the Constructor will be invoked five times. In addition, the destructor "Delete[]" is used( that is used for deleting the group of the several objects) for terminating variables. Hence all of the variables will be terminated completely, and while terminating the variables, the destructor will be invoked five times. 6) Consider the following given program and choose the most appropriate output from the given options:
Answer: B Explanation: In the above-given program, the derived class's object is storing in the base class pointer; while the object is destroyed, the program has never invoked the destructor of the Derived class. Therefore, it shows that the object is not destroyed at all; hence, in this case, the program may also behave undesirably. 7) Which of the following can be considered as the correct syntax for declaring an array of pointers of integers that has a size of 10 in C++?
Answer: C Explanation: To declare an array of integers' pointer, here we need to use the double-pointer array where every element is set of the pointer to the integers. Therefore the correct option is C. 8) Which of the following can be considered as the members that can be inherited but not accessible in any class?
Answer: C Explanation: The "Private" member of a class can be inherited by the child class. Still, the child class cannot access them (Or we can say that they are not accessible from the child class). 9) Which of the following can be used to create an abstract class in the C++ programming language?
Answer: A Explanation: A class must contain at least one declaration of the pure virtual function in itself to be called an abstract class. Therefore to make an abstract class, one has to declare at least one pure virtual function in that class. 10) Which of the following statements is correct about the class?
Answer: A Explanation: Generally, an object is an instance of a class, e.g., an object represents the class. 11) Which of the following statements is correct about the friend function in C++ programming language?
Answer: D Explanation: A friend function can access any member of a class without caring about the type of member it contains, such as public, private, and protected. 12) Which of the following statement is not true about C++?
Answer: C Explanation: In C, structures are not allowed to have member functions; while on the other hand, C++ allows the structure to have the member functions. Members of the class are generally private by default, and those of the structures are public. So it is a completely false statement that classes can not private members. 13) Which of the following given statement is completely true? I. In an object-oriented programming language, all the function calls are resolved at compile-time.
Answer: B Explanation: In a procedure programming language such as C, we do not have the concept of Polymorphism, so all function calls are resolved at the compile-time while, on the other hand, In an Object-Oriented language, through the concept of Polymorphism, all function calls cannot be resolved at the compile-time. 14) Which one of the following cannot be used with the virtual keyword?
Answer: A Explanation: In C++, we cannot use the virtual keyword with the Constructor because constructors are generally defined to initialize the object of a specific class; hence no other class requires the other class's object. 15) Which of the following is used for implementing the late binding?
Answer: C Explanation: A virtual function can be used for implementing the concept of late binding. For example - Binding the actual functions to their corresponding calls. 16) Which of the following statements supports that reusable code should be one of the desirable features of any language?
Answer: C Explanation: While reusing the existing code, we are not required to test/check that code, again and again, because it was already tested while it was written for the very first time. So the reusing the code defiantly helps in reducing the maintenance and testing time. While reusing the existing code, the compile-time most likely to be increased or remain the same, and it is obvious because we use the existing code in our program to save our time( or to include any specific functionality) by which the size of the overall program gets grows which is natural. 50) Which of the following statement is correct about the C++ programming language?
Answer: A Explanation: In C++, both types of static and dynamic checking are allowed. 18) Which of the following is not a kind of inheritance?
Answer: A Explanation: Among the above options, Distributed is only, which is not a type of inheritance, while Multiple, Multi-level, and the Hierarchal are the types of inheritance. 19) What will happen if "In a C++ program a class has no name"?
Answer: C Explanation: In the C++ program, if we use a class without assigning a name. As a result, it will not be going to have a destructor, but it will have the object. To understand it in more detail, consider the following program: Program #include 20) Which type of approach is used by the C++ language?
Answer: D Explanation: Generally, C++ uses the Bottom-up approach while other programming languages like C use the top-down approach. 21) Which of the following concept refers to adding new components to the program at the run time?
Answer: C Explanation: The dynamic loading is referred to as the concept of adding a new component to the program as it runs. 22) How can one implement the compile-time Polymorphism in the C++ programming language?
Answer: A Explanation: One can easily implement the Compile-time Polymorphism using the Template. 23) How can one implement the run-time Polymorphism in the C++ programming language?
Answer: In C++, one can implement the run-time Polymorphism by using the virtual functions and inheritance where the object decides which function to call. Explanation: C 24) Which of the following offers a programmer the facility of using a specific class object into other classes?
Answer: D Explanation: The composition is referred to as the concept of using objects of a specific class into several other classes. 25) Which one of the following cannot be a friend in C++ languages?
Answer: C Explanation: In general, an object of any class cannot be a friend of the same and any other class as well. However, there are some functions, operator, and classes which can be made a friend. 26) How are the references different from the pointer?
Answer: D Explanation: These are some basic reasons why the references are far different from the pointers. In the case of pointers "*" operator is required for dereferencing the value contain by it. However, the reference does not need any type of operator for deference. A Reference cannot be modified once it is initialized, but it is possible to do so in the case of a pointer. A pointer can be made Null, whereas a reference cannot be NULL. 27) Among the following given options, which can be considered as a member of a class?
Answer: B Explanation: Generally, the functions of any class are also considered as the member function of that class. 28) Which of the following refers to the wrapping of data and its functionality into a single individual entity?
Answer: C Explanation: In C++, the property of wrapping the data and its functionality into a single entity is known as Encapsulation ( e.g., Classes). 29) Which of the following refers to using the existing code instead of rewriting it?
Answer: A Explanation: With the help of the inheritance concept, one can use existing code instead of rewriting. We can do this by inheriting the properties of pre-written code in other parts of the code blocks. Therefore the user is not required to write the same code repeatedly. 30) Among the following, which shows the Multiple inheritances?
Answer: A Explanation: In multiple inheritances, a single class can inherit properties form more than one base class. 31) Which of the following statements is true about the C++ programming language?
Answer: D Explanation: C++ is a type of programming language which supports both the procedural ( or step by step instructions) and object-oriented through the concept of classes. 32) Among the following, which statement is correct about the Modularity?
Answer: B Explanation: Modularity refers to dividing a program into small independent code blocks or modules so that they can be easily called anywhere in the entire program where it is required. The concept of Modularity is very efficient and helpful for developers because it makes the program well structured and easy to understand. Hence the correct option is D. 33) Read the following program carefully and find out which concept from the given options is not used or missing in the following program? Program
Answer: A Explanation: As we can see in the above-given program, the variables X and Y both are private members, which means they both are hidden from the outside world of the class, so here the concept of abstraction is used. The other data members and their corresponding functions are stored in an individual class, so here the concept of Encapsulation is also used. In addition, Class B is derived from Class A, which means the concept of inheritance is used as well, but still, we didn't find and an overloaded function in any of the classes. Therefore the concept of Polymorphism is missing or not used in the given program. 34) Which of the following options correctly explains the concept of Polymorphism? a. b. c. d. None of the above Answer: A Explanation: The concept of Polymorphism refers to the overloading a function by changing either its number of passed arguments or changing its type. So you have only two options in which the function has named the same. Therefore one can easily find out that in option C, the type and the number of the argument all are the same, which definitely leads to an error that is wrong. However, the option in which the name of the function is the same has a different number of arguments, or different types is the correct option. So the correct answer is A. Next TopicC++ MCQ Part 2 |