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.Functions
B.Hardware
C.Algorithms
D.Data
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.Left-right
C.Bottom-up
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.static
B.public
C.protected
D.private
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.internal
B.protected
C.public
D.private
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 variable referencing an address
C.A function library
D.A blueprint for creating objects
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.Polymorphism
B.Inheritance
C.Instantiation
D.Encapsulation
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 equal to the sum of all members
B.Unions allocate memory equal to the largest member
C.Unions do not allocate memory
D.Unions allocate memory for all members simultaneously
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 type of pointer
B.A class with only static members
C.A user-defined type consisting of named integral constants
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.const
B.inline
C.register
D.static
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.Cannot access class members
B.Slower execution
C.Increases function call overhead
D.Increases binary executable size
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.Inline function
B.Virtual function
C.Static 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.Inside the main function
D.Outside the class definition
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.Null
B.Garbage value
C.1
D.0
Correct Answer: 0
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.Both static and non-static members
C.Only 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.clog
B.cin
C.cout
D.cerr
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.read()
B.getline()
C.scanf()
D.cin >>
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 can be assigned in any order
B.They must be assigned from right to left
C.They must be assigned from left to right
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.<iomanip>
B.<iostream>
C.<fstream>
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 null terminator
B.Inserts a new line and flushes the buffer
C.Inserts a new line only
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 parameter lists (signatures)
B.They have different return types only
C.They have different access modifiers
D.They are in different files
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.extern variableName
B.this->variableName
C.global.variableName
D.::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 accessible only to derived classes
B.A function that inherits from the class
C.A non-member function that can access private and protected members of a class
D.A function that is a member of the class
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 not mutual and not inherited
C.Friendship is 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.They are modified by the function
B.Their addresses are passed
C.Their values are copied to formal parameters
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 address
B.Call by reference
C.Call by name
D.Call by value
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 static variable
C.A base case
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.Only if it is a static member function
B.No, only global functions can be recursive
C.Only if it is a friend function
D.Yes, member functions can call themselves
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.File scope
C.Function scope
D.Block scope (inside the loop only)
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.2 bytes
B.4 bytes
C.1 byte
D.0 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.Encapsulation
B.Inheritance
C.Polymorphism
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.Only if it is static
B.Yes
C.Only if it is const
D.No
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 does not have a 'this' pointer
B.It can access non-static members directly
C.It can access static members
D.It can be called without an object
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.super
B.extern
C.virtual
D.friend
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.setw(10)
B.setfill(10)
C.setprecision(10)
D.width(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.Return type
B.Order of arguments
C.Number of arguments
D.Type of arguments
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.Data Segment
C.Code Segment
D.Stack
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.Only const
C.Only volatile
D.No
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.Runtime Error
B.The default values are used regardless
C.The provided arguments override the defaults
D.Compiler Error
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.They are the same
C.Object creates a Class
D.Class is a variable; Object is a type
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 by main() function
C.Accessible by derived classes
D.Accessible only within the class and by friends
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?
To link the function to the class, the scope resolution operator (::) is used with the class name.
Incorrect! Try again.
Did this save you a night before the exam?
LPU Notes is free, and it stays free. Ads cover part of the server bill.
The rest comes out of a student's own pocket: the domain, the storage,
and keeping the site up through the weeks everyone needs it at once.
The payment button didn't load. An ad blocker or a filtered network is the usual reason.
to try again.
Nothing here is ever locked, and nothing unlocks. Chip in only if it was worth it.
What it pays for →