1Which header file is strictly required to use basic input/output operations like cin and cout in C++?
A.<stdio.h>
B.<iostream>
C.<conio.h>
D.<iomanip>
Correct Answer: <iostream>
Explanation:The <iostream> header file defines the standard input/output stream objects in C++.
Incorrect! Try again.
2Which operator is used with the standard output stream (cout)?
A.>>
B.<<
C.::
D.->
Correct Answer: <<
Explanation:The insertion operator (<<) is used to send data to the output stream (cout).
Incorrect! Try again.
3In C++, what is the main focus of the Object-Oriented Programming paradigm compared to Procedural Programming?
A.Algorithms
B.Data
C.Functions
D.Hardware
Correct Answer: Data
Explanation:OOP focuses on data and the objects that manipulate that data, whereas procedural programming focuses on functions and logic.
Incorrect! Try again.
4Which approach is primarily followed in Object-Oriented Programming?
A.Top-down
B.Bottom-up
C.Left-right
D.Linear
Correct Answer: Bottom-up
Explanation:OOP generally follows a bottom-up approach where basic components (objects) are created first and then assembled to form complex systems.
Incorrect! Try again.
5What is the default access specifier for members of a Class in C++?
A.public
B.private
C.protected
D.static
Correct Answer: private
Explanation:By default, members of a class are private to ensure encapsulation.
Incorrect! Try again.
6What is the default access specifier for members of a Structure (struct) in C++?
A.public
B.private
C.protected
D.internal
Correct Answer: public
Explanation:In C++, structs default to public access to maintain backward compatibility with C.
Incorrect! Try again.
7Which of the following best describes a Class?
A.A built-in data type
B.A blueprint for creating objects
C.A function library
D.A variable referencing an address
Correct Answer: A blueprint for creating objects
Explanation:A class is a user-defined data type that acts as a template or blueprint for creating objects.
Incorrect! Try again.
8What is the process of creating an object from a class called?
A.Inheritance
B.Encapsulation
C.Instantiation
D.Polymorphism
Correct Answer: Instantiation
Explanation:Creating an instance (object) of a class is known as instantiation.
Incorrect! Try again.
9How does a Union differ from a Structure regarding memory allocation?
A.Unions allocate memory for all members simultaneously
B.Unions allocate memory equal to the sum of all members
C.Unions allocate memory equal to the largest member
D.Unions do not allocate memory
Correct Answer: Unions allocate memory equal to the largest member
Explanation:In a union, all members share the same memory location, so the size is equal to the size of its largest member.
Incorrect! Try again.
10What is an Enumeration (enum) in C++?
A.A class with only static members
B.A user-defined type consisting of named integral constants
C.A type of pointer
D.A function that returns multiple values
Correct Answer: A user-defined type consisting of named integral constants
Explanation:Enums are used to assign names to integral constants, making code easier to read and maintain.
Incorrect! Try again.
11Which operator is used to access a class member using an object instance?
A..
B.->
C.:
D.::
Correct Answer: .
Explanation:The dot operator (.) is used to access public members of a class through an object.
Incorrect! Try again.
12Which operator is used to access a class member using a pointer to an object?
A..
B.->
C.&
D.*
Correct Answer: ->
Explanation:The arrow operator (->) is used to access members when using a pointer to an object.
Incorrect! Try again.
13What is the keyword used to request the compiler to treat a function as an inline function?
A.static
B.inline
C.const
D.register
Correct Answer: inline
Explanation:The 'inline' keyword suggests to the compiler to expand the function code at the point of call to reduce overhead.
Incorrect! Try again.
14Which of the following is a disadvantage of inline functions?
A.Slower execution
B.Increases binary executable size
C.Cannot access class members
D.Increases function call overhead
Correct Answer: Increases binary executable size
Explanation:Since the code is duplicated at every call site, extensive use of inline functions can increase the size of the executable (code bloat).
Incorrect! Try again.
15If a member function is defined inside the class definition, it is treated as?
A.Static function
B.Virtual function
C.Inline function
D.Friend function
Correct Answer: Inline function
Explanation:Member functions defined strictly inside the class body are implicitly treated as inline functions by the compiler.
Incorrect! Try again.
16Where must a static data member be initialized?
A.Inside the class definition
B.Inside the constructor
C.Outside the class definition
D.Inside the main function
Correct Answer: Outside the class definition
Explanation:Static data members must be defined and initialized outside the class (usually in a .cpp file) to allocate memory for them.
Incorrect! Try again.
17What is the default initial value of a static integer data member if not explicitly initialized?
A.Garbage value
B.1
C.
D.Null
Correct Answer:
Explanation:Static variables are stored in the data segment and are zero-initialized by default.
Incorrect! Try again.
18A static member function can access which of the following?
A.Only static members
B.Only non-static members
C.Both static and non-static members
D.Only private members
Correct Answer: Only static members
Explanation:Static member functions do not have a 'this' pointer, so they can only access static data members and other static member functions.
Incorrect! Try again.
19Which standard stream is meant for error messages?
A.cout
B.cin
C.cerr
D.clog
Correct Answer: cerr
Explanation:cerr is the standard error stream used to output errors immediately (unbuffered).
Incorrect! Try again.
20Which function is used to read a full line of text, including spaces, from cin?
A.cin >>
B.getline()
C.read()
D.scanf()
Correct Answer: getline()
Explanation:getline(cin, stringVariable) reads a line of text from the input stream until a newline character is found.
Incorrect! Try again.
21What rule applies to Default Arguments in a function declaration?
A.They must be assigned from left to right
B.They must be assigned from right to left
C.They can be assigned in any order
D.Only the first argument can be default
Correct Answer: They must be assigned from right to left
Explanation:Once a default value is provided for a parameter, all subsequent parameters to its right must also have default values.
Incorrect! Try again.
22Which header file is required to use parameterized manipulators like setw()?
A.<iostream>
B.<fstream>
C.<iomanip>
D.<string>
Correct Answer: <iomanip>
Explanation:The <iomanip> header is needed for manipulators that take arguments, such as setw and setprecision.
Incorrect! Try again.
23What does the manipulator 'endl' do?
A.Inserts a new line only
B.Inserts a new line and flushes the buffer
C.Inserts a null terminator
D.Clears the screen
Correct Answer: Inserts a new line and flushes the buffer
Explanation:endl inserts a newline character ('\n') and forces the output buffer to flush.
Incorrect! Try again.
24Function overloading allows multiple functions to have the same name if:
A.They have different return types only
B.They have different parameter lists (signatures)
C.They are in different files
D.They have different access modifiers
Correct Answer: They have different parameter lists (signatures)
Explanation:Function overloading is based on having a unique signature (number or type of parameters). Return type alone is not sufficient.
Incorrect! Try again.
25Which operator is known as the Scope Resolution Operator?
A.:
B.::
C.->
D..
Correct Answer: ::
Explanation:The double colon (::) is the scope resolution operator, used to define methods outside classes or access global variables.
Incorrect! Try again.
26If a local variable has the same name as a global variable, how do you access the global variable?
A.global.variableName
B.extern variableName
C.::variableName
D.this->variableName
Correct Answer: ::variableName
Explanation:The scope resolution operator (::) placed before a variable name forces the compiler to look in the global scope.
Incorrect! Try again.
27What is a 'Friend Function'?
A.A function that is a member of the class
B.A non-member function that can access private and protected members of a class
C.A function that inherits from the class
D.A function accessible only to derived classes
Correct Answer: A non-member function that can access private and protected members of a class
Explanation:A friend function is defined outside the class scope but is granted permission to access non-public members.
Incorrect! Try again.
28Which statement about Friend Classes is true?
A.Friendship is mutual
B.Friendship is inherited
C.Friendship is not mutual and not inherited
D.Friendship is public by default
Correct Answer: Friendship is not mutual and not inherited
Explanation:If A is a friend of B, B is not automatically a friend of A, and children of A do not automatically become friends of B.
Incorrect! Try again.
29What is a Reference Variable?
A.A pointer to a memory address
B.An alias or alternative name for an existing variable
C.A variable that holds a constant value
D.A static variable
Correct Answer: An alias or alternative name for an existing variable
Explanation:A reference variable creates a new name for an existing memory location using the '&' symbol.
Incorrect! Try again.
30Which of the following syntax correctly declares a reference variable 'ref' for an integer 'a'?
A.int ref = &a;
B.int &ref = a;
C.int *ref = &a;
D.int ref = a;
Correct Answer: int &ref = a;
Explanation:The '&' operator in a declaration indicates a reference type.
Incorrect! Try again.
31In 'Call by Value', what happens to the actual arguments?
A.Their addresses are passed
B.Their values are copied to formal parameters
C.They are modified by the function
D.Aliases are created
Correct Answer: Their values are copied to formal parameters
Explanation:In call by value, a copy of the data is made. Changes in the function do not affect the original variable.
Incorrect! Try again.
32In 'Call by Reference', how are arguments passed?
A.By creating a copy
B.By passing the value
C.By passing an alias (reference) to the actual argument
D.By passing a pointer
Correct Answer: By passing an alias (reference) to the actual argument
Explanation:Call by reference passes the variable itself (via an alias), allowing the function to modify the original variable.
Incorrect! Try again.
33Which method of parameter passing requires the use of pointers in the function definition?
A.Call by value
B.Call by reference
C.Call by address
D.Call by name
Correct Answer: Call by address
Explanation:Call by address (or pointer) involves passing the address of a variable, which is received by a pointer in the function.
Incorrect! Try again.
34What is the necessary condition for a recursive function to terminate?
A.A loop
B.A base case
C.A static variable
D.A global variable
Correct Answer: A base case
Explanation:A recursive function requires a base case to stop the recursion, otherwise, it leads to infinite recursion and stack overflow.
Incorrect! Try again.
35Can a member function of a class be recursive?
A.No, only global functions can be recursive
B.Yes, member functions can call themselves
C.Only if it is a static member function
D.Only if it is a friend function
Correct Answer: Yes, member functions can call themselves
Explanation:Member functions follow standard function rules and can call themselves recursively.
Incorrect! Try again.
36What is the scope of a variable declared inside a for loop initialization?
A.Global scope
B.Function scope
C.Block scope (inside the loop only)
D.File scope
Correct Answer: Block scope (inside the loop only)
Explanation:In standard C++, variables declared in a for-loop initialization are only valid within that loop's block.
Incorrect! Try again.
37Which symbol allows cascading of input/output operations?
A.,
B.;
C.<< or >>
D.::
Correct Answer: << or >>
Explanation:The insertion (<<) and extraction (>>) operators return the stream object, allowing operations to be chained (cascaded).
Incorrect! Try again.
38What is the minimal size of an empty class in C++?
A.0 bytes
B.1 byte
C.2 bytes
D.4 bytes
Correct Answer: 1 byte
Explanation:The compiler allocates at least 1 byte to ensure that two different objects of the same class have different addresses.
Incorrect! Try again.
39Which feature of OOP allows hiding internal details and showing only functionality?
A.Polymorphism
B.Encapsulation
C.Inheritance
D.Abstraction
Correct Answer: Abstraction
Explanation:Data Abstraction refers to providing only essential information to the outside world and hiding their background details.
Incorrect! Try again.
40If a reference variable is declared, must it be initialized immediately?
A.Yes
B.No
C.Only if it is const
D.Only if it is static
Correct Answer: Yes
Explanation:References cannot be null and must be bound to an existing object immediately upon declaration.
Incorrect! Try again.
41Which of the following is NOT a characteristic of a static member function?
A.It can be called without an object
B.It does not have a 'this' pointer
C.It can access non-static members directly
D.It can access static members
Correct Answer: It can access non-static members directly
Explanation:Static member functions cannot access instance (non-static) members directly because they are not associated with a specific object instance.
Incorrect! Try again.
42What keyword allows a specific class to access private members of another class?
A.friend
B.super
C.extern
D.virtual
Correct Answer: friend
Explanation:Declaring friend class B; inside class A allows B to access A's private members.
Incorrect! Try again.
43Which of the following creates a Manipulator that sets the field width to 10?
A.width(10)
B.setw(10)
C.setfill(10)
D.setprecision(10)
Correct Answer: setw(10)
Explanation:setw(n) is the manipulator used to set the field width for the next output operation.
Incorrect! Try again.
44In function overloading, which of the following is NOT considered for differentiation?
A.Number of arguments
B.Type of arguments
C.Order of arguments
D.Return type
Correct Answer: Return type
Explanation:The compiler cannot distinguish functions based solely on return type; the parameter list must differ.
Incorrect! Try again.
45Which memory segment is used to store non-static local variables during recursion?
A.Heap
B.Stack
C.Data Segment
D.Code Segment
Correct Answer: Stack
Explanation:Recursion uses the call stack to store local variables and return addresses for each function call.
Incorrect! Try again.
46Can a 'friend' function be declared as 'const' or 'volatile'?
A.Yes
B.No
C.Only const
D.Only volatile
Correct Answer: No
Explanation:Friend functions are not members of the class, so they do not have a 'this' pointer, and thus qualifiers like const (which apply to 'this') are invalid.
Incorrect! Try again.
47What happens if you define a function with default arguments but provide all arguments during the call?
A.Compiler Error
B.Runtime Error
C.The provided arguments override the defaults
D.The default values are used regardless
Correct Answer: The provided arguments override the defaults
Explanation:Default arguments are only used if the caller omits those arguments. If provided, the explicit values are used.
Incorrect! Try again.
48How is a Class different from an Object?
A.Class is a logical entity; Object is a physical entity
B.Class is a variable; Object is a type
C.Object creates a Class
D.They are the same
Correct Answer: Class is a logical entity; Object is a physical entity
Explanation:A Class is a definition/template (logical), while an Object is an instance occupying memory (physical).
Incorrect! Try again.
49Which statement is true regarding the scope of class members defined as 'private'?
A.Accessible from anywhere
B.Accessible only within the class and by friends
C.Accessible by derived classes
D.Accessible by main() function
Correct Answer: Accessible only within the class and by friends
Explanation:Private members form the core of encapsulation and are restricted to the class itself and explicitly declared friends.
Incorrect! Try again.
50What is the correct way to define a member function outside the class?