0

C++ Programming

Description: This test consists of 25 questions about C++ programming language.
Number of Questions: 25
Created by:
Tags: C Programming Java/Oracle /C/C++
Attempted 0/25 Correct 0 Score 0

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()


Correct Option: C
Explanation:

This function determines the first occurrence of the character in the given string and if no match is found, then a NULL pointer is returned.

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


Correct Option: C
Explanation:

Yes, this operator is used in token parsing to concatenate the two variables or tokens.

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

  1. &

  2. >>

  3. delete

  4. scope resolution operator (::)

  5. new


Correct Option: D
Explanation:

We cannot overload scope resolution operator (::) in C++.

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)


Correct Option: E
Explanation:

Both the options are true.

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


Correct Option: C
Explanation:

Yes, this is the main advantage of using new operator over malloc() in C++.

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


Correct Option: C
Explanation:

This is a false statement about virtual function in C++ as we can create a virtual function without defining the base class, which is known as pure virtual function.

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


Correct Option: A
Explanation:

We can access private and protected members both in the class by making the friend function of that class.

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)


Correct Option: C
Explanation:

This statement is true about class and the structure in C++ and this is the only difference between them.

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

  1. LINE

  2. FILE

  3. TIME

  4. DATE

  5. All of the above


Correct Option: E
Explanation:

All are predefined C++ macros.

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


Correct Option: D
Explanation:

This mode defines that all output to the file is to be appended to the end.

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)


Correct Option: D
Explanation:

Both the options are true about mutable keyword in C++.

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


Correct Option: C
Explanation:

This is not true as we can also use typedef keyword to define an alias for a function in C++ and it can be used as function pointer.

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


Correct Option: C
Explanation:

Abstraction determines only the interface not implementation. It can separate the interface with implementation.

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


Correct Option: D
Explanation:

Yes, both the options determine the true concept.

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)


Correct Option: B
Explanation:

This is not a true statement. There is a necessary condition to make the destructor as virtual as our program can not manage the memory allocated by downward subclasses and it may be leaked.

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

  1. <iostream>

  2. <iomanip>

  3. <fstream>

  4. <stdio.h>

  5. None of these


Correct Option: A
Explanation:

This header file defines the cerr object in C++.

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


Correct Option: C
Explanation:

Extern variables can be used to access in a file which is declared and defined in some other files, so these have a global scope outside the particular class and hence, they are called global variables.

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


Correct Option: C
Explanation:

The const keyword makes the value of the variable constant and we cannot change its value, so it will give compile time error.

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


Correct Option: A
Explanation:

This is a false statement as C++ determines multilevel inheritance and in that case, a single derived class can inherit from two or more base classes.

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


Correct Option: A
Explanation:

Yes, signed modifier allows both positive and negative values.

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.


Correct Option: D
Explanation:

No, inline function may increase the function size of your program, so this is the false statement about inline function in C++.

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


Correct Option: C
Explanation:

This statement is true. In that case, the whole body of the function is placed when the function call is made every time in the program, so if the function is large it will affect the speed and memory of the program.

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


Correct Option: D
Explanation:

Yes, both options are the false statements, so this option is correct according to the question.

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)


Correct Option: D
Explanation:

It is a user-defined data type in C++.

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


Correct Option: E
Explanation:

Yes, these all statements are true about namespace in C++.

- Hide questions