C++ MCQ

50 MULTIPLES CHOICE QUESTIONS ON C++

1. C++ is called a(n) _________?

  1. Structured programming language
  2. Event-driven programming language
  3. Object-oriented programming language
  4. None of these
   

Correct answer- The correct answer is option C.

Reason- C++ is basically a successor of C language and since it included classes, objects, encapsulation, abstraction and many other characteristics, it is called the object oriented programming language.

2. The escape pattern for carriage return is:

  1. ./w
  2. ./n
  3. ./r
  4. ./g
   

Correct answer-The correct answer is option C.

Reason-./r helps to escape a sequence and to carriage return to the text. It tells the terminal to return to the start point of a text and not to the next like endl; or /n;.

3. In flowchart rectangle symbol signifies:

  1. Connector
  2. Process
  3. Decision
  4. Input/output
   

Correct answer-The correct answer is option B.

Reason- A rectangle symbol is generally used to signify or state a process/procedure in a flowchart. The process can be anything varying from a basic statement such as C = 20 to an operation of addition for example ADD = C+D and several others.

4. The arithmetic or mathematical operators in C++ language are:

  1. Binary operator
  2. Unary operator
  3. Ternary operator
  4. None of these
   

Correct answer- The correct answer is option A.

Reason- Binary operators generally take two arguments and perform the function that is listed that is the reason they are also used for arithmetic operators in C++ language.

5. In switch case, each case label may be an integer constant or:

  1. String constant
  2. Real constant
  3. None of these
  4. Character constant
   

Correct answer-The correct answer is option is D.

Reason- In switch case labels, the case labels should be constant expressions as they have to be calculated at the compile time.

6. What is correct pattern to print a message in C++ language?

  1. Cout<<”Hello world!”;
  2. Printf<<Hello world!;
  3. Cout<<”Hello world!;
  4. None of the above
   

Correct answer- The correct answer is option A.

Reason- Option A is the correct option as in all the other options some elements of C++ is missing and if we proceed with them and execute the program, then the compiler will throw an error. So, the correct syntax is option A.

7. Usage of the virtual functions means

  1. Nesting of functions
  2. Dynamic binding
  3. Overloading of functions
  4. Static binding
   

Correct answer-The correct option is B.

Reason- Whenever we call a virtual function then it is simply solved at the run-time itself by inspecting the kind of object which is basically calling the function. This type of procedure s called as dynamic binding.

8. Which of the following is the correct identifier?

  1. VAR_123
  2. _varname@
  3. #var_name
  4. None of the above
   

Correct answer- The correct answer is option A.

Reason- Identifiers have a case sensitive nature, there are certain rules for defining identifiers in C++ language. An identifier cannot begin with an underscore or special characters. It cannot start with numbers. And so option A is correct.

9. Declaration of a pointer more than once may cause ____________.

  1. Abort
  2. Error
  3. Trap
  4. Null
   

Correct answer- The correct answer is option C.

Reason- Pointers holds the address of certain specific variable and if we declare them more than once, then the compiler might get confuse as to consider which of the following and so it may lead to a condition such as trap.

10. The programming language that has the ability to create new data types is called ___________.

  1. reprehensible
  2. Encapsulated
  3. Extensible
  4. All of the above
   

Correct answer- The correct answer is option C.

Reason- Extensible programming language is basically an elementary language which helps in providing the basic computational facilities. It also comprises of a meta-language that has the potential of modifying the basic language.

11. Which of the following options is used to allocate space in the memory for an array?

  1. Realloc
  2. Malloc
  3. None of the above
  4. Both a and b
   

Correct answer- The correct answer is option D.

Reason- The malloc function in C++ language is used for the dynamic allocation of memory and it allocates a single large block of memory that contains a specific size whereas the realloc function in C++ language is used to dynamically switch the previously allocated memory.

12. Which of the following is known as the address operator?

  1. @
  2. #
  3. $
  4. None of the above
   

Correct answer- The correct answer is option D.

Reason- If we wish to print the address of any variable then we have to use the ‘&’ operator, without this the compiler will throw an error if we will try to print the address of any variable.

>

13. The pointers in C++ are used for implementing the concept of which of the following?

  1. Array
  2. Polymorphism
  3. Encapsulation
  4. Classes
   

Correct answer-The correct answer is option B.

Reason- Polymorphism is a greek word which means many forms. It implies the capability of displaying a function or message in more than one forms and if we look close enough pointers portray similar functionality.

14. The data item of a structure is generally called _____________?

  1. Field
  2. Elements
  3. Objects
  4. All of these
   

Correct answer-The correct answer is option D.

Reason- In structures, each and every data item is referred to as member, they are also referred to as fields, elements and objects. This is the reason why option (D) is correct choice.

15. In C++ language, the function of a class is mainly called _______?

  1. Attributes
  2. Methods
  3. Member functions
  4. Both a and b
   

Correct answer-The correct answer is option C.

Reason- A member function of a class is particularly a function that should be defined within the class itself. It generally operates on any object of the class as it is the member of the class.

16. The derived class is also known as ______________?

  1. Parent class
  2. Child class
  3. Originated class
  4. Both a and b
   

Correct answer-The correct answer is option D.

Reason- In C++ language, we can inherit the characteristics of a base class and impart them into another class called as the derived class. The base class is known as the parent class as the characteristics are drawn from it. On the contrary, derived class is known as the child class as it inherits the characteristics just like human beings.

17. The term ‘Friend’ is used to define a:

  1. Friend class
  2. Friend function
  3. Friend constructor
  4. All of the above
   

Correct answer-The correct answer is option D.

Reason- A friend function is a function that grants you the permission to access all the private and protected data of a class. It is generally defined outside the class scope. A friend can be a class, constructor or even just a function.

18. How many loop structure are available in C++?

  1. 3
  2. 8
  3. 7
  4. 5
  5. None of these
   

Correct answer-The correct answer is option A.

Reason- A loop can be defined as a function which helps us in repeating and checking the condition till the time it gets a false value and then exit the function or condition. There are three types of loops present in the C++ language that are for loop, while loop and lastly do-while loop.

19. Which of the following is the starting point of a pointer?

  1. NULL
  2. &
  3. 0
  4. None of the above
   

Correct answer-The correct answer is option C.

Reason- In any language, we start with 0 as it is more natural to parse the values and continue rather than relying on alphabets or numeric characters or x and y.

20. Among all of these, which one is a loop statement?

  1. If-else
  2. While
  3. Do-while
  4. Switch
  5. All of these
   

Correct answer-The correct answer is option B.

Reason- A loop can be defined as a function which helps us in repeating and checking the condition till the time it gets a false value and then exit the function or condition. There are three types of loops present in the C++ language that are for loop, while loop and lastly do-while loop.

21. The C++ language comes under which category of object oriented programming?

  1. Partial or semi
  2. Pure
  3. Mixed breed
  4. Semi collision
   

Correct answer-The correct answer is option A.

Reason- Pure object oriented languages are the ones which treats everything in their source code as the objects rather than having data types like int, float, bool, etc. Languages like C++ contains data types such as  int, float, bool and several others. So this is the reason why C++ is called partial or semi object oriented language.

22. Choose which one of the following statements is true about the C++ language.

  1. C++ stands to be a pure language.
  2. C++ is a procedural language.
  3. C++ is both procedural as well as object-oriented language.
  4. C++ is not object oriented.
   

Correct answer-The correct answer is option C.

Reason- A procedural language is the one where there is a set of instructions present for the execution of certain statements as well as functions in a sequential manner. On the other hand, object oriented language is the one which contains classes, polymorphism, inheritance, encapsulation and several others. This is the reason C++ is both procedural as well as object oriented language.

23. Which statement best defines the concept of inheritance?

  1. Reusability and extension of classes of C++.
  2. Copying the functions of one class.
  3. Duplicate of another class.
  4. Reusing existing classes.
   

Correct answer-The correct answer is option A.

Reason- Inheritance is generally defined as the mechanism where we reuse the already present classes without redefining them which automatically creates a hierarchy.

24. Which of the following statements is correct about modularity?

  1. It refers to hiding a program.
  2. It refers to dividing the parts of a program into smaller and independent parts.
  3. It refers to the automatic generation of various other member functions.
  4. It refers to the overloading a particular program.
   

Correct answer-The correct answer is option B.

Reason- In C++ language, modularity is generally defined as a mechanism in which the program is splitted into various parts through the usage of classes. Each class present then is termed as the module.

25. What do you mean by the term polymorphism?

  1. Many parts
  2. Many functions
  3. Function containership
  4. Many forms
  5. None of the above
   

Correct answer-The correct answer is option D.

Reason- Polymorphism is a greek word which means many forms. It implies the capability of displaying a function or message in more than one form. Practically, it means diverse definitions for a single name function which have the same name but have distinguishable functionalities.

26. What is the role of cout in C++?

  1. It is used to overload the functions.
  2. It is used to copy a given statement.
  3. It is used to display or print the output on the screen.
  4. All of the above.
   

Correct answer-The correct answer is option C.

Reason- The cout function is C++ is used for the outflow of data. It is an output stream which is generally used to print the message passed by the user.

27. True or False: We can use Cout function in C language?

  1. True
  2. False
  3. Both a and b.
  4. Neither a nor b.
   

Correct answer-The correct answer is option B.

Reason- Cout is an output stream which is generally used to print the message passed by the user. Cout is only used in the C++ language, in C language we use the printf function for the printing mechanism.

28. Can we use printf function in C++ language?

  1. False
  2. True
  3. Both a and b.
   

Correct answer-The correct answer is option B.

Reason- Printf is a function which is used to print the output of a program. It is generally used in both C and C++ languages to print the data.

29. What is the correct syntax for adding two numbers to show the concepts of returning objects?

  1. Cout<<”the sum of a and b is”<<(a+b)<<endl;
  2. Cout<<the sum of a and b is”<<(a+b)<<endl;
  3. Cout<<”the sum of a and b is”<<(a+b)<<endl
  4. Cout<<”the sum of a and b is”<<”(a+b)”<<endl;
   

Correct answer-The correct answer is option A.

Reason- Option A is considered to be the correct answer of the following question as all the other options present in the question has some type of coding error and if we go through with any one of them then it will throw an error at the time of compiling.

30. What is containership?

  1. Nesting of functions.
  2. Overloading of functions.
  3. Copying of functions.
  4. Inheritance.
  5. None of the above.
   

Correct answer-The correct answer is option A.

Reason- When a class contains the objects or the members of any other class, then this kind of relationship between the two classes is called containership. It is also popularly known as the nesting of functions.

31. Are virtual functions present in C language?

  1. Yes
  2. No
   

Correct answer-The correct answer is option B.

Reason- No, virtual functions are a feature of object-oriented programming and C language is not an object oriented programming.

32. What do you mean by the term overriding?

  1. When a function of the base class is re-defined in the derived class.
  2. When functions have different data types.
  3. When functions are declared public in a class.
  4. When functions are nested together and overloading happens.
  5. All of the above.
   

Correct answer-The correct answer is option A.

Reason- Overriding is defined as when a function of parent class is modified in the child class, and then it is called as the overriding of function. It is a concept of the runtime polymorphism.

33. Which of the following statements define the term templates?

  1. It is basic entity or structure for creating family of classes, functions and objects.
  2. It is the structure for objects.
  3. It is a pre-defined parameter for creating functions within a program.
  4. None of the above.
   

Correct answer-The correct answer is option A.

Reason-Templates are considered to be the most powerful feature of C++ language. It is generally a layout in which gives us the access to define the generic classes or the generic functions and supports the programming.

34. What is recursion?

  1. It is the process of nesting the functions.
  2. It is a process of repeating items in a self-similar way.
  3. It is a process of replicating its functions.
  4. It is a process of creating copy of the existing items.
  5. None of the above.
   

Correct answer-The correct answer is option B.

Reason- Recursion in C++ can be defined as the method where a function keeps calling itself unless and until a certain condition is reached and then it stops. It always has a base case along with a recursive condition.

35. Various functions with same function name can be defined as long as they have difference in their parameters. This phenomenon is called as?

  1. Inheritance
  2. Polymorphism
  3. Data handling
  4. Function overloading
   

Correct answer-The correct answer is option D.

Reason- Function overloading is another important aspect of the C++ language, where functions with same function name can be defined as long as they have difference in their parameters.

36. Which of the following allows function overloading in C++?

  1. Type
  2. Number of arguments
  3. Parameters
  4. Type and number of arguments
   

Correct answer-The correct answer is option D.

Reason- function overloading is generally a mechanism or procedure through which we can distinguish between the functions having the same name but different parameters or arguments. That is the reasons it is necessary to have both the type as well as the number of the arguments being passed on to verify the functions.

37. What do you mean by throw contracts?

  1. A program catches an exception with an exception handler.
  2. It identifies a block of code for which particular exceptions will be activated.
  3. A program throws an exception when a specific problem shows up.
  4. None of the above.
   

Correct answer-The correct answer is option C.

Reason-In C++, exception handling is generally categorized into three aspects that are try, catch and throw. Each of them has their own features but the throw exception handling mainly focuses on throwing an exception when a problem in particular shows up.

38. Who invented C++ language?

  1. Dannis Ritchie
  2. Bjarne Stroustrup
  3. Albert Einstein
  4. Charles babbage
  5. None of the above
   

Correct answer-The correct answer is option B.

Reason-C++ language was invented by Bjarne Stroustrup in the year 1998. He was a Danish computer scientist and he developed C++ language in the Bell laboratory since the year 1979.

39. What are user-defined header files?

  1. It is pre-defined and comes with the compiler.
  2. It is fixed in the structure of classes.
  3. It declares the parts of the operating system to the interfaces.
  4. It is generally written by the programmer.
  5. None of the above
   

Correct answer-The correct answer is option D.

Reason- Header filesthat consist of a macro definition and comes with an extension of .h is generally termed as user-defined header files. These are the files that are written by the programmer itself.

40. Which of the following statements define inline functions?

  1. It is a special type of constructor which creates new objects which are generally a copy of an existing one.
  2. If a function is inline, the compiler places a copy of the code of that function at each given point where the function is being called at the compile time.
  3. It is a type of function which provides us the access to get all the private and protected members of the class.
  4. It is a type of function which is used to switch the values in the variables.
  5. None of the above.
   

Correct answer-The correct answer is option B.

Reason-It is a powerful concept of the C++ language that is generally seen being used with classes. When a function is inline, the compiler places a copy of the output of the first executable statement and then keeps pasting the copy of the output rather than executing the program each time. It saves the memory as well as the time.

41. Correct the following syntax of the following C++ function:

int main()

{

register int i = 1;

int ptr = &i ;

cout<<*ptr ;

return 0;

}

  1. int i = “1”;
  2. int *ptr = &i ;
  3. cout<<”*ptr” ;
  4. int main();
  5. none of the above.
   

Correct answer-The correct answer is option B.

Reason- In the above mentioned source code, when we don’t put the * while specifying the pointer, it will not treat ptr as a pointer rather it will see ptr as a variable and will throw an error at the compiling time.

42. Which of the following statement is true about new operator?

  1. They are used for dynamic allocation of memory.
  2. The new operator generally allocates a memory and returns a pointer to the start of it.
  3. It helps in the freeing of the memory while a program is running.
  4. It helps in freeing the previously allocated memory.
    1. i
    2. ii
    3. Both i and ii.
    4. iii
    5. iv
    6. Both iii and iv.
    7. None of the above.
   

Correct answer-The correct answer is option C.

Reason- The new operator in C++ language particularly denotes a request for memory allocation. If the requested memory is available then the new operator registers that block of memory and returns the address of the allocated memory to the pointer variable.

43. How many types of constructors are present in the C++ language?

  1. 4
  2. 5
  3. 6
  4. 7
  5. 3
  6. None of the above.
   

Correct answer-The correct answer is option E.

Reason-A constructor is generally a special type of member function of class which is of the same name as that of a class. It is defined within a class. There are three types of constructors present in the C++ language that are default constructor, parametrized constructor and copy constructor.

44. Which of the following statements best describe the concept of Hybrid inheritance?

  1. It is a type of method where one or more than one type of inheritance are combined together and put into use.
  2. It is a type of method where a class can be re-defined in another subclass.
  3. It is a type of method or function where we can access the private members of a class and use its data.
  4. It is a type of method which helps us in creating replicas of a particular function.
  5. Both a and b.
  6. Both a and d.
  7. None of the above.
   

Correct answer-The correct answer is option A.

Reason- Hybrid inheritance is a special type of inheritance in which one or more than one type of inheritance are combined together and put into use.

45. What is early and late binding?

  1. In the process of early binding, the function call is known at the compile time whereas in late binding, all information which is needed is not known at the compile time.
  2. In the process of early binding, the function call is made automatically whereas in late binding, the function call is user-defined.
  3. In the process of early binding, it manages the collections of the objects whereas in late binding, it manages the functionality of classes.
  4. None of the above.
   

Correct answer-The correct answer is option A.

Reason-Binding is a mechanism of converting the identifiers into addresses. Early binding is matching the function call with correct function definition at the compile time whereas in late binding, all information which is needed is not known at the compile time.

46. What does STL stands for?

  1. Standard transfer library
  2. Standard tragic library
  3. Standard template library
  4. Static template library
   

Correct answer-The correct answer is option C.

Reason-STL stands for the standard template library. It is generally a set of template classes which is used for the purpose of implementing data structures in the C++ language.

47. Which of the following data type is provided by C++ language but not C language?

  1. Bool
  2. Int
  3. Float
  4. Char
   

Correct answer-The correct answer is option A.

Reason- Boolean data types are the data types which checks whether a given condition is true or false. If it’s a true condition, they pass the value 1 as an output whereas if the condition is false, they pass the value 0 as an output.

48. What will be the output of the following C++ code?

#include<iostream>

Using namespace std;

Int main()

{

Cout<<”Hello World”<<endl;

Return 0;

}

  1. Hello
  2. Hello world
  3. World
  4. Hello world endl
   

Correct answer-The correct answer is option B.

Reason- Option B is correct as after the extratersion operator we have Hello World in the double quotes which are the correct syntax for printing the above mentioned code.

49. Which of the following statement(s) is correct about STL?

  1. It is a general-purpose templatized classes and functions that implements commonly used algorithms and data structures like vectors, queues, stacks, lists, etc.
  2. It is used in defining functions that have similar signatures but different parameters.
  3. It is a powerful set of C++ template classes.
  4. They are used for the nesting of functions.
    1. (i) is correct.
    2. Both (i) and (iii) is correct.
    3. (iv) is correct
    4. None of the above.
   

Correct answer-The correct answer is option B.

Reason- STL stands for the standard template library. It is generally a set of template classes which is used for the purpose of implementing data structures in the C++ language.

50. Which turns out to be more functional while calling the C++ function?

  1. Call by object
  2. Call by value
  3. Call by variable
  4. Call by reference
  5. Both b and d.
  6. All of the above.
   

Correct answer-The correct answer is option D.

Reason- Call by reference in the C++ language can be easily defined as when the function gives us the access to pass the parameters to the functions by the reference and not directly.