C++ Programming
This test consists of 25 questions about C++ programming language.
Questions
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?
- strcpy()
- strstr()
- strchr()
- Both (2) and (3)
- strcmp()
Which of the following operators is/are used to merge two tokens in C++ preprocessor?
- #define
- #
- ##
- Both (2) and (3)
- None of these
Which of the following operators cannot be overloaded in C++?
- &
- >>
- delete
- scope resolution operator (::)
- new
Which of the following modifiers can be applied to char data types in C++?
- signed
- unsigned
- long
- short
- Both (1) and (2)
What is/are the advantage(s) of using new operator over malloc() in C++?
- malloc() is not used in C++.
- malloc() is type-safe but new is not type-safe.
- malloc() only allocates memory, while new operator allocates memory as well as constructs objects in C++.
- Both (2) and (3)
- None of these
Which of the following statements is/are false about virtual function in C++?
- Virtual function is used to achieve dynamic binding in C++.
- We cannot instantiate the base class by defining pure virtual function in that class.
- We cannot create a virtual function without definition inside the base class.
- Both (2) and (3) are false.
- None of these
What is the role of friend function in C++?
- Private and protected data members of the class can be accessed by defining the friend function.
- Only protected data members of the class can be accessed by defining the friend function.
- Only private data members of the class can be accessed by defining the friend function.
- Only public and protected data members of the class can be accessed by defining the friend function.
- None of these
Which of the following statements show(s) the difference between the class and structure in C++?
- A class is user-defined data type in C++, whereas a structure is not.
- A class has private access specifier by default, whereas a structure has protected access specifier in C++.
- A class has private access specifier by default, whereas a structure has public access specifier in C++.
- Both (1) and (3)
- Both (2) and (3)
Which of the following is/are predefined C++ macro(s)?
- LINE
- FILE
- TIME
- DATE
- All of the above
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?
- ios::in
- ios::out
- ios::ate
- ios::app
- None of these
What is/are the role(s) of mutable variable in C++?
- We can use this variable in the member variable of the class.
- This keyword is used to modify the const objects of the mutable data members.
- This keyword is used to make the objects of data members as constant.
- Both (1) and (2)
- Both (1) and (3)
Which of the following is/are false about typedef keyword in C++?
- It is used to create an alias for a known data type.
- typedef keyword can be used with unsigned char data type.
- typedef keyword cannot be used to define an alias for a function.
- Both (2) and (3)
- None of these
Which of the following statements is false?
- C++ is an object-oriented language.
- Encapsulation determines the binding of data variables and functions into a single unit.
- Data abstraction is a design approach with implementation in C++.
- Polymorphism can be achieved in C++ by virtual function.
- None of these
If a class is defined with the name 'A', then what will be the valid declaration(s) for the constructor of the class?
- A()
- A::A()
- ~A()
- Both (1) and (2)
- All of the above
Which of the following statements is/are false?
- We cannot create virtual constructor in C++.
- We cannot create virtual destructors in C++.
- We can define pure virtual destructor also in our program.
- Both (2) and (3)
- Both (1) and (2)
Which of the following header files defines the standard error stream (cerr) object in C++ language?
- <iostream></iostream><iostream>
- <iomanip></iomanip><iomanip>
- <fstream></fstream><fstream>
- <stdio.h></stdio.h><stdio.h>
- None of these
Which of the following variables are called global variables in C++?
- Static variables
- Register variables
- Extern variables
- Auto variables
- None of these
What will be the output of the following code?
int main{ const int x = 1; x++; }
- 2
- 1
- Compile time error
- 0
- None of these
Which of the following statements is/are not true about inheritance in C++?
- There is no multiple inheritance in C++.
- C++ supports multilevel inheritance.
- Hybrid inheritance is possible in C++.
- Both (1) and (3)
- None of these
Which of the following modifiers allow(s) negative value in C++?
- signed
- unsigned
- Both (1) and (2)
- float
- None of these
Which of the following is not true about inline function in C++?
- 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.
- To make a function inline, we should place inline keyword before that function.
- Inline function reduces function calling overhead.
- Inline function decreases the function size.
- Inline function can make the header file size large.
Which of the following is/are the limitation(s) of inline function in C++?
- Inline function cannot be used with small functions.
- Inline function cannot be used in place of macros.
- Inline function is not applicable for the complicated function.
- Both (2) and (3)
- All of the above
Which of the following statements is/are not true?
- There are two types of overloading, i.e. function overloading and operator overloading in C++.
- It is not necessary to initialise the static variables.
- We can have a static virtual function in C++.
- Both (2) and (3)
- None of these
Which of the following is/are not the built-in data type(s) in C++?
- bool
- void
- wchar_t
- enum
- Both (3) and (4)
Which of the following statements is/are true about namespace in C++?
- We cannot put a semicolon after the namespace definition.
- A namespace definition can be applied to multiple files.
- We can use namespace in the program by scope resolution operator.
- Only (1) and (2)
- All of the above