Therefore, the correct answer is FILE *fopen(const char *filename, const char *mode);.
55. What is the function of the mode ‘w+’?
Write and Open for both reading and writing
Open for both reading and writing
Open for writing
Open for both reading and appending in binary mode
Show me the answer
Answer: 2) Open for both reading and writing
Explanation:
The mode w+ opens a file for both reading and writing. If the file exists, its contents are truncated. If the file does not exist, it is created.
Therefore, the correct answer is Open for both reading and writing.
56. What is the function of the mode ‘a+’?
Write and Open for both reading and writing
Open for both reading and writing
Open for reading and appending
Open for both reading and appending in binary mode
Show me the answer
Answer: 3) Open for reading and appending
Explanation:
The mode a+ opens a file for both reading and appending. If the file exists, new data is appended to the end of the file. If the file does not exist, it is created.
Therefore, the correct answer is Open for reading and appending.
57. If the mode includes 'b' after the initial letter, what does it indicate?
Text file
Binary file
Big file
None of the Above
Show me the answer
Answer: 2) Binary file
Explanation:
The b in the mode (e.g., rb, wb, ab) indicates that the file is opened in binary mode. Binary mode is used for non-text files, such as images or executable files.
Therefore, the correct answer is Binary file.
58. What does tmpfile() return when it could not create the file?
Stream
NULL
Both Stream and NULL
No result
Show me the answer
Answer: 2) NULL
Explanation:
The tmpfile() function creates a temporary file and returns a pointer to the file stream. If the file cannot be created, it returns NULL.
Therefore, the correct answer is NULL.
59. fwrite() can be used only with files that are opened in binary mode:
True
False
Depends on the Situation
All of the Above
Show me the answer
Answer: 1) True
Explanation:
The fwrite() function is used to write data to a file in binary mode. It is typically used with files opened in binary mode (e.g., wb, ab).
Therefore, the correct answer is True.
60. What are the functions that help to randomly access the file?
fseek()
ftell()
rewind()
All of the Above
Show me the answer
Answer: 4) All of the Above
Explanation:
The following functions are used for random access in files:
fseek(): Moves the file pointer to a specific location.
ftell(): Returns the current position of the file pointer.
rewind(): Moves the file pointer to the beginning of the file.
Therefore, the correct answer is All of the Above.
61. Data stored in a file can be accessed in:
Sequential and Random
Semi-Sequential and Random
Random only
All of the Above
Show me the answer
Answer: 1) Sequential and Random
Explanation:
Data in a file can be accessed in two ways:
Sequential access: Data is read or written in a linear manner.
Random access: Data can be accessed at any position using functions like fseek() and ftell().
Therefore, the correct answer is Sequential and Random.
62. The causes of function overloading are:
Type Conversion
Function with Default Arguments
Function with pass by reference
All of the Above
Show me the answer
Answer: 4) All of the Above
Explanation:
Function overloading in C++ can occur due to:
Type Conversion: Different parameter types.
Default Arguments: Functions with optional parameters.
Pass by Reference: Functions with reference parameters.
Therefore, the correct answer is All of the Above.
63. Which of the following is true?
Existing operators can only be overloaded, but new operators cannot be overloaded
The overloaded operator contains at least one operand of the user-defined data type
We cannot use a friend function to overload certain operators
All of the Above
Show me the answer
Answer: 2) The overloaded operator contains at least one operand of the user-defined data type
Explanation:
Operator overloading in C++ requires at least one operand to be of a user-defined data type. For example:
#include <iostream>
using namespace std;
class Complex {
int real, imag; // Private data members to store real and imaginary parts
public:
// Constructor to initialize real and imaginary parts
Complex(int r = 0, int i = 0) : real(r), imag(i) {}
// Overloading the + operator
Complex operator+(Complex c) {
Complex temp; // Temporary Complex object to store the result
temp.real = real + c.real; // Add the real parts
temp.imag = imag + c.imag; // Add the imaginary parts
return temp; // Return the result
}
// Function to display the Complex number
void display() const {
cout << real << " + " << imag << "i" << endl;
}
};
int main() {
Complex c1(3, 4), c2(1, 2); // Create two Complex objects
Complex c3 = c1 + c2; // Add two Complex objects using overloaded +
cout << "Result: ";
c3.display(); // Display the result
return 0; // Indicate successful execution
}
Therefore, the correct answer is The overloaded operator contains at least one operand of the user-defined data type.
64. Which of the following operators cannot be overloaded?
Scope operator (::) and Sizeof
Member selector(.) and member pointer selector(*)
Ternary operator(?:)
All of the Above
Show me the answer
Answer: 4) All of the Above
Explanation:
The following operators cannot be overloaded in C++:
Scope operator (::)
Sizeof operator (sizeof)
Member selector (.)
Member pointer selector (.*)
Ternary operator (?:)
Therefore, the correct answer is All of the Above.
65. Which of the following can be overloaded?
Methods
Constructors
Indexed Properties
All of the Above
Show me the answer
Answer: 4) All of the Above
Explanation:
In C++, the following can be overloaded:
Methods: Functions with the same name but different parameters.
Constructors: Multiple constructors with different parameters.
Therefore, the correct answer is All of the Above.
66. The function whose definition can be substituted at a place where its function call is made is:
Inline Function
Offline Function
Friend Function
Normal Function
Show me the answer
Answer: 1) Inline Function
Explanation:
An inline function is a function whose definition is substituted at the place where it is called. This avoids the overhead of a function call.
For example:
#include <iostream>
using namespace std;
// Inline function to add two integers
inline int add(int a, int b) {
return a + b; // Returns the sum of a and b
}
int main() {
int result = add(5, 10); // The code of add() is substituted here
cout << "Result: " << result << endl; // Output: Result: 15
return 0; // Indicates successful execution
}
Therefore, the correct answer is Inline Function.
67. How many ways are there to invoke a function in C++?
1
3
2
4
Show me the answer
Answer: 3) 2
Explanation:
In C++, a function can be invoked in two ways:
Call by Value: Passes the value of the actual parameter.
Call by Reference: Passes the address of the actual parameter.
Therefore, the correct answer is 2.
68. At what time does the inline function get expanded?
Compile time
Run time
At the end
Depends on the program
Show me the answer
Answer: 1) Compile time
Explanation:
An inline function is expanded at compile time. The compiler replaces the function call with the actual code of the function.
Therefore, the correct answer is Compile time.
69. In a Function Prototype, where should default parameters appear?
Leftmost side
Rightmost side
In the middle
Anywhere
Show me the answer
Answer: 2) Rightmost side
Explanation:
Default parameters in a function prototype must appear on the rightmost side.
For example:
#include <iostream>
using namespace std;
// Function declaration with default parameters for 'b' and 'c'
void print(int a, int b = 10, int c = 20);
int main() {
print(5); // Output: 5 10 20 (default values for 'b' and 'c')
print(5, 15); // Output: 5 15 20 (overrides 'b', default for 'c')
print(5, 15, 25); // Output: 5 15 25 (overrides all default values)
return 0; // Indicates successful execution
}
// Function definition
void print(int a, int b, int c) {
cout << a << " " << b << " " << c << endl;
}
Therefore, the correct answer is Rightmost side.
70. Which one of the following is correct?
Only one parameter of a function can be a default parameter
A minimum of one parameter of a function must be a default parameter
All the parameters of a function can be default parameters
No parameter of a function can be default
Show me the answer
Answer: 3) All the parameters of a function can be default parameters
Explanation:
In C++, all parameters of a function can have default values.
For example:
#include <iostream>
using namespace std;
void print(int a = 1, int b = 2, int c = 3) {
cout << a << " " << b << " " << c; // Prints the values of a, b, and c
}
int main() {
print(); // Output: 1 2 3 (uses default values)
print(10); // Output: 10 2 3 (overrides only 'a', uses default for 'b' and 'c')
print(10, 20); // Output: 10 20 3 (overrides 'a' and 'b', uses default for 'c')
print(10, 20, 30); // Output: 10 20 30 (overrides all default values)
return 0; // Indicates successful execution
}
Therefore, the correct answer is All the parameters of a function can be default parameters.
71. Execution of the program starts from:
Main
Void
User Defined
Loop
Show me the answer
Answer: 1) Main
Explanation:
In C++, the execution of a program always starts from the main() function.
For example:
int main() {
cout << "Hello, World!";
return 0;
}
Therefore, the correct answer is Main.
72. In the program, if user and default values are given, the program will take:
Default Value
User Value
NULL Value
Own Value
Show me the answer
Answer: 2) User Value
Explanation:
If both user and default values are provided, the program will use the user value.
For example:
#include <iostream>
using namespace std;
void print(int a = 10) {
cout << a; // Prints the value of 'a'
}
int main() {
print(20); // Output: 20 (user value overrides default value)
return 0; // Return 0 to indicate successful execution
}
Therefore, the correct answer is User Value.
73. The default return type of a function is:
INT
FLOAT
CHAR
VOID
Show me the answer
Answer: 4) VOID
Explanation:
If no return type is specified for a function, the default return type is int in C. However, in C++, the return type must always be explicitly specified. Therefore, the correct answer is VOID.
74. Which of the following is correct?
An object is a runtime entity and created at runtime
An object is an entity that has state and behavior
An object is an instance of a class
All of the Above
Show me the answer
Answer: 4) All of the Above
Explanation:
An object in C++ is:
A runtime entity created at runtime.
An entity that has state (data members) and behavior (member functions).
An instance of a class.
Therefore, the correct answer is All of the Above.
75. Which of the following entities can be connected by the dot operator?
A class object and a member of that class
A class object and a class
A class member and a class object
All of the Above
Show me the answer
Answer: 1) A class object and a member of that class
Explanation:
The dot operator (.) is used to access members of a class through an object.
For example:
class Student {
public: int id;
};
Student s1;
s1.id = 101; // Dot operator connects object and member
Therefore, the correct answer is A class object and a member of that class.
76. Which of the following is also known as an instance of a class?
Member Functions
Class
Object
Member Variables
Show me the answer
Answer: 3) Object
Explanation:
An object is an instance of a class. It represents a specific realization of the class, with its own state (data members) and behavior (member functions). For example: class Student { public: int id; }; Student s1; // s1 is an object (instance of the Student class)
Therefore, the correct answer is Object.
77. How many objects can be created from an abstract class?
0
1
2
3
Show me the answer
Answer: 1) 0
Explanation:
An abstract class in C++ cannot be instantiated directly. It is meant to be a base class for other classes. Therefore, no objects can be created from an abstract class.
Therefore, the correct answer is 0.
78. We can overload:
Operator
Function
Both A & B
Object
Show me the answer
Answer: 3) Both A & B
Explanation:
In C++, both operators and functions can be overloaded. For example:
Function overloading: Multiple functions with the same name but different parameters.
Operator overloading: Defining custom behavior for operators like +, -, etc.
Therefore, the correct answer is Both A & B.
79. How many types of access specifiers are there?
2
3
4
5
Show me the answer
Answer: 2) 3
Explanation:
In C++, there are three access specifiers:
Public: Members are accessible from outside the class.
Private: Members are accessible only within the class.
Protected: Members are accessible within the class and derived classes.
Therefore, the correct answer is 3.
80. In a single class, which of the following can be used together?
Private Only
Public Only
Protected Only
All
Show me the answer
Answer: 4) All
Explanation:
In a single class, all three access specifiers (private, public, and protected) can be used together. For example: class Student { private: int id; public: string name; protected: float marks; };
Therefore, the correct answer is All.
81. Which of the following can restrict class members from being inherited?
Private Only
Public Only
Protected Only
All
Show me the answer
Answer: 1) Private Only
Explanation:Private members of a class cannot be inherited by derived classes. They are accessible only within the class itself.
Therefore, the correct answer is Private Only.
82. Which access specifier is used for data members of a class?
Private
Default
Protected
Public
Show me the answer
Answer: 1) Private
Explanation:
Data members of a class are typically declared as private to enforce encapsulation and prevent direct access from outside the class.
Therefore, the correct answer is Private.
83. Which access specifier should be used for member functions of a class?
Private
Default
Protected
Public
Show me the answer
Answer: 4) Public
Explanation:
Member functions that need to be accessed from outside the class should be declared as public. For example: class Student { public: void display() { cout << "Hello, World!"; } };
Therefore, the correct answer is Public.
84. In which access specifier can all the parent class members be inherited and accessed from outside the class?
Private
Default
Protected
Public
Show me the answer
Answer: 4) Public
Explanation:
When a class is inherited using the public access specifier, all public members of the parent class remain public in the derived class and can be accessed from outside.
Therefore, the correct answer is Public.
85. Which access specifier should be used in a class where the instances can’t be created?
Private default constructor
All private constructors
Public
Protected
Show me the answer
Answer: 2) All private constructors
Explanation:
If all constructors of a class are declared as private, instances of the class cannot be created from outside the class. This is often used in singleton design patterns.
Therefore, the correct answer is All private constructors.
hich of the following is the scope resolution operator?
::
:::
&
&&
Show me the answer
Answer: 1) ::
Explanation:
The scope resolution operator in C++ is ::.
It is used to:
Access global variables when a local variable with the same name exists.
Define member functions outside the class.
Access static members of a class.
Access members of a namespace.
Therefore, the correct answer is ::.
88. Which of the following is the address operator?
@
&
#
%
Show me the answer
Answer: 2) &
Explanation:
The address operator in C++ is &.
It is used to:
Get the memory address of a variable.
Pass arguments by reference in functions.
For example:
int x = 10;
int* ptr = &x; // ptr stores the address of x
Therefore, the correct answer is &.
89. To become a pure object-oriented programming language, which features must be supported?
Encapsulation
Inheritance
Polymorphism
All of the Above
Show me the answer
Answer: 4) All of the Above
Explanation:
A pure object-oriented programming language must support:
Encapsulation: Bundling data and methods that operate on the data.
Inheritance: Deriving a class from another class to reuse code.
Polymorphism: Allowing objects of different classes to be treated as objects of a common superclass.
Therefore, the correct answer is All of the Above.
90. The scope resolution operator is used to:
Overload a function in inheritance
Override a function in inheritance
Both of the Above
None of the Above
Show me the answer
Answer: 3) Both of the Above
Explanation:
The scope resolution operator (::) is used to:
Overload a function: Define a function outside the class.
Override a function: Access the base class version of an overridden function in derived classes.
Therefore, the correct answer is Both of the Above.
91. The scope resolution operator is used for:
To specify a particular class
Provides a conceptual framework
Addition
All of the Above
Show me the answer
Answer: 1) To specify a particular class
Explanation:
The scope resolution operator (::) is primarily used to:
Specify a particular class or namespace when accessing its members.
Resolve ambiguity when multiple classes or namespaces have members with the same name.
Therefore, the correct answer is To specify a particular class.
92. Which class allows declaring only one object of it?
Abstract Class
Singleton class
Friend class
All of the Above
Show me the answer
Answer: 2) Singleton class
Explanation:
A Singleton class is designed to allow only one instance of itself to be created.
This is achieved by:
Making the constructor private.
Providing a static method to access the single instance.
Therefore, the correct answer is Singleton class.
93. Which of the following is a member of a class?
Static function
Constant function
Virtual function
All of the Above
Show me the answer
Answer: 4) All of the Above
Explanation:
All the following are members of a class:
Static function: A function that belongs to the class rather than an instance.
Constant function: A function that does not modify the state of the object.
Virtual function: A function that can be overridden in derived classes.
Therefore, the correct answer is All of the Above.
94. The other name used for functions inside a class is:
Own Functions
Member Functions
Inside Functions
None of the Above
Show me the answer
Answer: 2) Member Functions
Explanation:
Functions defined inside a class are called member functions.
They operate on the data members of the class and can be public, private, or protected.
Therefore, the correct answer is Member Functions.
95. Generally, how many types of member functions are there in C++?
2
3
4
5
Show me the answer
Answer: 3) 4
Explanation:
The main types of member functions in C++ are:
Simple member functions: Regular functions defined inside a class.
Static member functions: Functions that belong to the class rather than an instance.
Const member functions: Functions that do not modify the state of the object.
Virtual member functions: Functions that can be overridden in derived classes.
Therefore, the correct answer is 4.
96. In the main function, how can a static member function be called?
Using the Dot Operator
Using the Arrow Operator
Using the Dot or Arrow Operator
Using the Dot, Arrow, or using the 'scope resolution operator with class name'
Show me the answer
Answer: 4) Using the Dot, Arrow, or using the 'scope resolution operator with class name'
Explanation:
A static member function can be called in the following ways:
Using the dot operator (.) with an object.
Using the arrow operator (->) with a pointer to an object.
Using the scope resolution operator (::) with the class name (no object required).
For example:
class MyClass {
public:
static void myFunction() {
cout << "Static function called!";
}
};
int main() {
MyClass::myFunction(); // Using scope resolution operator
MyClass obj;
obj.myFunction(); // Using dot operator
MyClass* ptr = &obj;
ptr->myFunction(); // Using arrow operator
return 0;
}
Therefore, the correct answer is Using the Dot, Arrow, or using the 'scope resolution operator with class name'.
97. Which of the following is correct?
If no constructor is explicitly declared, the compiler automatically creates a default constructor with no data members (variables) or initialization
A constructor is used in classes to initialize data members of the class to avoid errors/segmentation faults.
A copy constructor is a constructor to initialize an object with the values of another object
All of the Above
Show me the answer
Answer: 4) All of the Above
Explanation:
All the statements are correct:
If no constructor is explicitly declared, the compiler provides a default constructor.
A constructor is used to initialize data members of a class.
A copy constructor initializes an object using another object of the same class.
Therefore, the correct answer is All of the Above.
98. A constructor is used to:
Modify the data whenever required
Destroy an object
Initialize the data members of an object when it is created
None of the Above
Show me the answer
Answer: 3) Initialize the data members of an object when it is created
Explanation:
The primary purpose of a constructor is to initialize the data members of an object when it is created.
It is automatically called when an object is instantiated.
Therefore, the correct answer is Initialize the data members of an object when it is created.
99. What will happen if we forget to define a constructor inside a class?
Error Occurs
Segmentation faults
The compiler provides a default constructor
Destructor called
Show me the answer
Answer: 3) The compiler provides a default constructor
Explanation:
If no constructor is defined in a class, the compiler automatically provides a default constructor.
This default constructor does not initialize data members but allows object creation.
Therefore, the correct answer is The compiler provides a default constructor.
100. How many types of constructors exist in C++?
2
3
4
5
Show me the answer
Answer: 2) 3
Explanation:
The main types of constructors in C++ are:
Default Constructor: No parameters.
Parameterized Constructor: Takes parameters to initialize data members.
Copy Constructor: Initializes an object using another object of the same class.