C++ Programming

This test consists of 25 questions about C++ programming language.

25 Questions Published

Questions

Question 1 Multiple Choice (Single Answer)

Which of the following string functions in C++ returns a pointer to the first occurrence of character in string and returns NULL, if the specified character is not found in the string?

  1. strcpy()
  2. strstr()
  3. strchr()
  4. Both (2) and (3)
  5. strcmp()
Question 2 Multiple Choice (Single Answer)

Which of the following operators is/are used to merge two tokens in C++ preprocessor?

  1. #define
  2. #
  3. ##
  4. Both (2) and (3)
  5. None of these
Question 3 Multiple Choice (Single Answer)

Which of the following operators cannot be overloaded in C++?

  1. &
  2. >>
  3. delete
  4. scope resolution operator (::)
  5. new
Question 4 Multiple Choice (Single Answer)

Which of the following modifiers can be applied to char data types in C++?

  1. signed
  2. unsigned
  3. long
  4. short
  5. Both (1) and (2)
Question 5 Multiple Choice (Single Answer)

What is/are the advantage(s) of using new operator over malloc() in C++?

  1. malloc() is not used in C++.
  2. malloc() is type-safe but new is not type-safe.
  3. malloc() only allocates memory, while new operator allocates memory as well as constructs objects in C++.
  4. Both (2) and (3)
  5. None of these
Question 6 Multiple Choice (Single Answer)

Which of the following statements is/are false about virtual function in C++?

  1. Virtual function is used to achieve dynamic binding in C++.
  2. We cannot instantiate the base class by defining pure virtual function in that class.
  3. We cannot create a virtual function without definition inside the base class.
  4. Both (2) and (3) are false.
  5. None of these
Question 7 Multiple Choice (Single Answer)

What is the role of friend function in C++?

  1. Private and protected data members of the class can be accessed by defining the friend function.
  2. Only protected data members of the class can be accessed by defining the friend function.
  3. Only private data members of the class can be accessed by defining the friend function.
  4. Only public and protected data members of the class can be accessed by defining the friend function.
  5. None of these
Question 8 Multiple Choice (Single Answer)

Which of the following statements show(s) the difference between the class and structure in C++?

  1. A class is user-defined data type in C++, whereas a structure is not.
  2. A class has private access specifier by default, whereas a structure has protected access specifier in C++.
  3. A class has private access specifier by default, whereas a structure has public access specifier in C++.
  4. Both (1) and (3)
  5. Both (2) and (3)
Question 9 Multiple Choice (Single Answer)

Which of the following is/are predefined C++ macro(s)?

  1. LINE
  2. FILE
  3. TIME
  4. DATE
  5. All of the above
Question 10 Multiple Choice (Single Answer)

Which of the following modes of the open() function in C++ file handling defines that all the output to the file is to be appended to the end?

  1. ios::in
  2. ios::out
  3. ios::ate
  4. ios::app
  5. None of these
Question 11 Multiple Choice (Single Answer)

What is/are the role(s) of mutable variable in C++?

  1. We can use this variable in the member variable of the class.
  2. This keyword is used to modify the const objects of the mutable data members.
  3. This keyword is used to make the objects of data members as constant.
  4. Both (1) and (2)
  5. Both (1) and (3)
Question 12 Multiple Choice (Single Answer)

Which of the following is/are false about typedef keyword in C++?

  1. It is used to create an alias for a known data type.
  2. typedef keyword can be used with unsigned char data type.
  3. typedef keyword cannot be used to define an alias for a function.
  4. Both (2) and (3)
  5. None of these
Question 13 Multiple Choice (Single Answer)

Which of the following statements is false?

  1. C++ is an object-oriented language.
  2. Encapsulation determines the binding of data variables and functions into a single unit.
  3. Data abstraction is a design approach with implementation in C++.
  4. Polymorphism can be achieved in C++ by virtual function.
  5. None of these
Question 14 Multiple Choice (Single Answer)

If a class is defined with the name 'A', then what will be the valid declaration(s) for the constructor of the class?

  1. A()
  2. A::A()
  3. ~A()
  4. Both (1) and (2)
  5. All of the above
Question 15 Multiple Choice (Single Answer)

Which of the following statements is/are false?

  1. We cannot create virtual constructor in C++.
  2. We cannot create virtual destructors in C++.
  3. We can define pure virtual destructor also in our program.
  4. Both (2) and (3)
  5. Both (1) and (2)
Question 16 Multiple Choice (Single Answer)

Which of the following header files defines the standard error stream (cerr) object in C++ language?

  1. <iostream></iostream><iostream>
  2. <iomanip></iomanip><iomanip>
  3. <fstream></fstream><fstream>
  4. <stdio.h></stdio.h><stdio.h>
  5. None of these
Question 17 Multiple Choice (Single Answer)

Which of the following variables are called global variables in C++?

  1. Static variables
  2. Register variables
  3. Extern variables
  4. Auto variables
  5. None of these
Question 18 Multiple Choice (Single Answer)

What will be the output of the following code?
int main{ const int x = 1; x++; }

  1. 2
  2. 1
  3. Compile time error
  4. 0
  5. None of these
Question 19 Multiple Choice (Single Answer)

Which of the following statements is/are not true about inheritance in C++?

  1. There is no multiple inheritance in C++.
  2. C++ supports multilevel inheritance.
  3. Hybrid inheritance is possible in C++.
  4. Both (1) and (3)
  5. None of these
Question 20 Multiple Choice (Single Answer)

Which of the following modifiers allow(s) negative value in C++?

  1. signed
  2. unsigned
  3. Both (1) and (2)
  4. float
  5. None of these
Question 21 Multiple Choice (Single Answer)

Which of the following is not true about inline function in C++?

  1. This function instructs the compiler to insert copy of the code of that function at each point wherever that function is called at compile time.
  2. To make a function inline, we should place inline keyword before that function.
  3. Inline function reduces function calling overhead.
  4. Inline function decreases the function size.
  5. Inline function can make the header file size large.
Question 22 Multiple Choice (Single Answer)

Which of the following is/are the limitation(s) of inline function in C++?

  1. Inline function cannot be used with small functions.
  2. Inline function cannot be used in place of macros.
  3. Inline function is not applicable for the complicated function.
  4. Both (2) and (3)
  5. All of the above
Question 23 Multiple Choice (Single Answer)

Which of the following statements is/are not true?

  1. There are two types of overloading, i.e. function overloading and operator overloading in C++.
  2. It is not necessary to initialise the static variables.
  3. We can have a static virtual function in C++.
  4. Both (2) and (3)
  5. None of these
Question 24 Multiple Choice (Single Answer)

Which of the following is/are not the built-in data type(s) in C++?

  1. bool
  2. void
  3. wchar_t
  4. enum
  5. Both (3) and (4)
Question 25 Multiple Choice (Single Answer)

Which of the following statements is/are true about namespace in C++?

  1. We cannot put a semicolon after the namespace definition.
  2. A namespace definition can be applied to multiple files.
  3. We can use namespace in the program by scope resolution operator.
  4. Only (1) and (2)
  5. All of the above