1In C++, which operator is used to access the memory address of a variable?
A.
B.
C.
D.$.$
Correct Answer:
Explanation:The address-of operator returns the memory address of the operand.
Incorrect! Try again.
2What is the primary difference between malloc() in C and new in C++?
A.malloc() calls the constructor, new does not.
B.new calls the constructor, malloc() does not.
C.Both call the constructor.
D.Neither calls the constructor.
Correct Answer: new calls the constructor, malloc() does not.
Explanation:new is an operator that allocates memory and initializes the object by calling its constructor, whereas malloc() is a library function that only allocates raw memory bytes.
Incorrect! Try again.
3In the context of Parameter Passing, what happens in Pass by Value?
A.The address of the actual parameter is passed to the function.
B.A copy of the actual parameter's value is passed to the function.
C.An alias to the actual parameter is created.
D.The function can directly modify the original variable.
Correct Answer: A copy of the actual parameter's value is passed to the function.
Explanation:In Pass by Value, the value of the argument is copied into the formal parameter. Changes made to the parameter inside the function do not affect the original argument.
Incorrect! Try again.
4Which storage class in C/C++ preserves the value of a local variable between function calls?
A.auto
B.register
C.static
D.extern
Correct Answer: static
Explanation:A static local variable is initialized only once and retains its value between function calls, as it is stored in the data segment rather than the stack.
Incorrect! Try again.
5Which concept in OOP allows a class to derive properties and behavior from another class?
A.Polymorphism
B.Encapsulation
C.Inheritance
D.Abstraction
Correct Answer: Inheritance
Explanation:Inheritance is the mechanism where a new class (derived class) acquires the properties and methods of an existing class (base class).
Incorrect! Try again.
6In Java, objects are stored in which area of memory?
A.Stack
B.Heap
C.Register
D.ROM
Correct Answer: Heap
Explanation:In Java, all objects are dynamically allocated on the Heap. The references to these objects may be stored on the Stack.
Incorrect! Try again.
7What is the result of dereferencing a NULL pointer in C++?
A.It returns 0.
B.It returns a random integer.
C.It causes a segmentation fault or undefined behavior.
D.It creates a new object.
Correct Answer: It causes a segmentation fault or undefined behavior.
Explanation:Accessing memory at address 0 (NULL) is illegal in most operating systems, leading to a crash or undefined behavior.
Incorrect! Try again.
8Which of the following creates a Memory Leak?
A.Allocating memory on the stack.
B.Allocating memory on the heap and failing to free it.
C.Using a global variable.
D.Passing a pointer by reference.
Correct Answer: Allocating memory on the heap and failing to free it.
Explanation:A memory leak occurs when dynamically allocated memory (Heap) is no longer needed but is not released back to the operating system.
Incorrect! Try again.
9What is Dynamic Binding (Late Binding)?
A.Linking a function call to the code to be executed at compile time.
B.Linking a function call to the code to be executed at runtime.
C.Binding variable names to memory addresses during coding.
D.Hardcoding function addresses.
Correct Answer: Linking a function call to the code to be executed at runtime.
Explanation:Dynamic binding resolves function calls at runtime, typically used to implement polymorphism (e.g., Virtual Functions in C++).
Incorrect! Try again.
10In C++, what is the this pointer?
A.A pointer to the base class.
B.A pointer to the derived class.
C.A const pointer that points to the object invoking the member function.
D.A global pointer accessible by all classes.
Correct Answer: A const pointer that points to the object invoking the member function.
Explanation:this is an implicit pointer passed to all non-static member functions, pointing to the object on which the function is called.
Incorrect! Try again.
11Which Java keyword is used to prevent a class from being inherited?
A.static
B.const
C.final
D.abstract
Correct Answer: final
Explanation:In Java, declaring a class as final prevents it from being subclassed.
Incorrect! Try again.
12In C, if int arr[5] = {1, 2, 3, 4, 5}; and int *p = arr;, what is the value of *(p + 2)?
A.1
B.2
C.3
D.Address of 3
Correct Answer: 3
Explanation:p points to arr[0]. p + 2 points to arr[2]. Dereferencing *(p + 2) gives the value at index 2, which is 3.
Incorrect! Try again.
13What is a Dangling Pointer?
A.A pointer pointing to NULL.
B.A pointer pointing to a memory location that has been deleted or freed.
C.A pointer that has not been initialized.
D.A pointer to a constant value.
Correct Answer: A pointer pointing to a memory location that has been deleted or freed.
Explanation:If the memory a pointer points to is deallocated, but the pointer is not set to NULL, it becomes a dangling pointer, pointing to invalid memory.
Incorrect! Try again.
14Which feature of OOP describes wrapping data and methods into a single unit?
A.Inheritance
B.Polymorphism
C.Encapsulation
D.Recursion
Correct Answer: Encapsulation
Explanation:Encapsulation is the bundling of data (variables) and methods (functions) that operate on that data into a single unit (class).
Incorrect! Try again.
15In Java, parameter passing is always:
A.Pass by Reference
B.Pass by Value
C.Pass by Pointer
D.Pass by Name
Correct Answer: Pass by Value
Explanation:Java strictly uses Pass by Value. For objects, the 'value' passed is the reference (pointer/address) to the object, not the object itself, but the mechanism is still passing that reference by value.
Incorrect! Try again.
16What is the purpose of a Virtual Destructor in C++?
A.To delete objects faster.
B.To ensure the derived class destructor is called when deleting via a base class pointer.
C.To prevent the class from being instantiated.
D.To allow multiple inheritance.
Correct Answer: To ensure the derived class destructor is called when deleting via a base class pointer.
Explanation:If a base class destructor is not virtual, deleting a derived object through a base pointer results in undefined behavior (usually only the base destructor runs), causing memory leaks.
Incorrect! Try again.
17Which area of memory is used for recursive function calls and local variables?
A.Heap
B.Stack
C.Data Segment
D.Code Segment
Correct Answer: Stack
Explanation:The Stack is used for static memory allocation, including function call frames (activation records), local variables, and return addresses.
Incorrect! Try again.
18In C++, what is the size of an empty class?
A.0 bytes
B.1 byte
C.2 bytes
D.4 bytes
Correct Answer: 1 byte
Explanation:The C++ standard ensures that an empty class has a size of at least 1 byte to ensure that two different objects will have different addresses.
Incorrect! Try again.
19What is the default access specifier for members of a class in C++?
A.public
B.private
C.protected
D.internal
Correct Answer: private
Explanation:In C++, class members are private by default. In struct, they are public by default.
Incorrect! Try again.
20Which of the following correctly declares a pointer to a function accepting an integer and returning void in C++?
A.void *func(int);
B.void (*func)(int);
C.void func(int *);
D.*void func(int);
Correct Answer: void (*func)(int);
Explanation:The syntax ReturnType (*PointerName)(ParameterTypes) creates a function pointer. Parentheses around *func are necessary to distinguish it from a function returning a pointer.
Incorrect! Try again.
21What implies the concept of Polymorphism?
A.One interface, multiple methods.
B.Hiding data implementation.
C.Creating new classes from old ones.
D.Automatic memory management.
Correct Answer: One interface, multiple methods.
Explanation:Polymorphism allows objects to be treated as instances of their parent class, enabling a single interface (method call) to behave differently based on the actual object type.
Incorrect! Try again.
22What is the output of sizeof(char*) on a standard 64-bit architecture?
A.1
B.4
C.8
D.16
Correct Answer: 8
Explanation:On a 64-bit architecture, memory addresses are 64 bits long, so a pointer (regardless of the data type it points to) occupies 8 bytes.
Incorrect! Try again.
23In Java, what mechanism handles the deallocation of memory on the Heap?
A.Destructors
B.free() function
C.delete operator
D.Garbage Collector
Correct Answer: Garbage Collector
Explanation:Java uses automatic Garbage Collection to identify and free memory that is no longer reachable by the program, relieving the programmer of manual memory management.
Incorrect! Try again.
24What is a Reference in C++?
A.A pointer that can be null.
B.An alias for an existing variable.
C.A duplicate copy of a variable.
D.A variable stored in the CPU register.
Correct Answer: An alias for an existing variable.
Explanation:A reference is essentially an alias or an alternative name for an existing variable. It must be initialized upon declaration and cannot be null.
Incorrect! Try again.
25Which problem arises when two pointers point to the same memory location and one is freed?
A.Memory Leak
B.Dangling Pointer
C.Stack Overflow
D.Buffer Underrun
Correct Answer: Dangling Pointer
Explanation:When one pointer frees the memory, the second pointer still holds the address of that now-invalid memory, becoming a dangling pointer.
Incorrect! Try again.
26What is the Diamond Problem in C++?
A.A memory leak in a loop.
B.Ambiguity arising from multiple inheritance where two base classes inherit from a common ancestor.
C.A syntax error in template classes.
D.An issue with pointer arithmetic on 2D arrays.
Correct Answer: Ambiguity arising from multiple inheritance where two base classes inherit from a common ancestor.
Explanation:The Diamond Problem occurs when a class inherits from two classes that both inherit from the same super-parent, potentially leading to two copies of the super-parent's members.
Incorrect! Try again.
27What is a Pure Virtual Function in C++?
A.A function with no return type.
B.A function that cannot be overridden.
C.A virtual function initialized to 0, forcing derived classes to override it.
D.A function that does not use any variables.
Correct Answer: A virtual function initialized to 0, forcing derived classes to override it.
Explanation:Syntax: virtual void func() = 0;. This makes the class Abstract, and the function must be implemented by concrete derived classes.
Incorrect! Try again.
28In the context of parameter passing, what is an Activation Record?
A.A log of compilation errors.
B.A data structure stored on the stack containing local variables and return addresses for a function call.
C.A record of all heap allocations.
D.A database of class methods.
Correct Answer: A data structure stored on the stack containing local variables and return addresses for a function call.
Explanation:Also known as a stack frame, the activation record holds the state of a specific function invocation.
Incorrect! Try again.
29Which of the following is true about Pass by Reference?
A.It requires more memory than pass by value.
B.It passes a copy of the object.
C.It avoids copying large objects, improving performance.
D.It prevents the function from modifying the argument.
Correct Answer: It avoids copying large objects, improving performance.
Explanation:Pass by Reference passes the address/alias, avoiding the overhead of copying the entire object data, which is efficient for large structures/classes.
Incorrect! Try again.
30In C++, int &r = x; is an example of:
A.Pointer declaration
B.Reference declaration
C.Bitwise AND
D.Address-of operator
Correct Answer: Reference declaration
Explanation:The & in a type declaration context (left side of assignment) signifies a reference variable.
Incorrect! Try again.
31What defines a Deep Copy?
A.Copying only the pointer address.
B.Copying the object and allocating new memory for the data pointed to by the object.
C.Copying the object bit-by-bit.
D.Using the assignment operator =.
Correct Answer: Copying the object and allocating new memory for the data pointed to by the object.
Explanation:A deep copy duplicates the actual data pointed to by pointers within the object, ensuring the new object is fully independent of the original.
Incorrect! Try again.
32Which operator is used to release memory allocated by new[]?
A.delete
B.delete[]
C.free
D.remove
Correct Answer: delete[]
Explanation:When allocating arrays with new[], you must use delete[] to ensure destructors are called for every element in the array.
Incorrect! Try again.
33Which of the following is NOT a principle of OOP?
A.Encapsulation
B.Inheritance
C.Polymorphism
D.Compilation
Correct Answer: Compilation
Explanation:Compilation is a process of converting code to machine language, not a conceptual pillar of Object-Oriented Programming.
Incorrect! Try again.
34In Java, String objects are immutable. What does this mean?
A.They cannot be deleted.
B.Their values cannot be changed after creation.
C.They are stored in the stack only.
D.They cannot be passed to functions.
Correct Answer: Their values cannot be changed after creation.
Explanation:Immutable means once a String object is created, its content cannot be altered. Operations that appear to modify it actually create a new String object.
Incorrect! Try again.
35What is the difference between struct and class in C++ regarding inheritance?
A.Structs cannot inherit.
B.Structs inherit publicly by default; classes inherit privately by default.
C.Classes cannot inherit from structs.
D.There is no difference.
Correct Answer: Structs inherit publicly by default; classes inherit privately by default.
Explanation:The only technical differences are default access specifiers for members and default inheritance type (public for struct, private for class).
Incorrect! Try again.
36If a recursive function does not have a base case, what error occurs?
A.Heap Overflow
B.Stack Overflow
C.Compilation Error
D.Linker Error
Correct Answer: Stack Overflow
Explanation:Infinite recursion fills up the stack with activation records until no space remains, causing a Stack Overflow.
Incorrect! Try again.
37What is Function Overloading?
A.Defining multiple functions with the same name but different parameters.
B.Defining a function in the base and derived class with the same signature.
C.Calling a function inside itself.
D.Passing too many parameters to a function.
Correct Answer: Defining multiple functions with the same name but different parameters.
Explanation:Overloading allows multiple functions with the same name to exist if their parameter lists (types or number of arguments) differ.
Incorrect! Try again.
38In C++, the keyword friend allows a function to:
A.Access private and protected members of a class.
B.Inherit from the class.
C.Delete the class object.
D.Become a member of the class.
Correct Answer: Access private and protected members of a class.
Explanation:A friend function is not a member of the class but is granted permission to access its non-public members.
Incorrect! Try again.
39Which segment of memory stores global and static variables?
A.Stack
B.Heap
C.Data Segment
D.Code Segment
Correct Answer: Data Segment
Explanation:Global and static variables are stored in the Data Segment (initialized) or BSS (uninitialized) and exist for the lifetime of the program.
Incorrect! Try again.
40What is the outcome of void *p; in C++?
A.It declares a pointer that returns nothing.
B.It declares a generic pointer that can hold the address of any data type.
C.It is a syntax error.
D.It declares a null pointer.
Correct Answer: It declares a generic pointer that can hold the address of any data type.
Explanation:A void pointer is a generic pointer. It cannot be dereferenced directly without casting because the compiler doesn't know the size of the data it points to.
Incorrect! Try again.
41Which of the following best describes an Abstract Class?
A.A class that has no variables.
B.A class that cannot be instantiated and is meant to be subclassed.
C.A class with only static methods.
D.A class that is hidden from other files.
Correct Answer: A class that cannot be instantiated and is meant to be subclassed.
Explanation:Abstract classes serve as blueprints. In C++, they contain at least one pure virtual function. In Java, they are declared with the abstract keyword.
Incorrect! Try again.
42In C++, what is the syntax to access a member of a class using a pointer to an object?
A..
B.
C.
D.
Correct Answer:
Explanation:The arrow operator () is used to access members of a structure or class via a pointer. ptr->member is equivalent to (*ptr).member.
Incorrect! Try again.
43What is RAII (Resource Acquisition Is Initialization) in C++?
A.A method to initialize arrays.
B.A programming idiom where resource management is tied to object lifetime.
C.A compiler optimization technique.
D.A way to pass parameters.
Correct Answer: A programming idiom where resource management is tied to object lifetime.
Explanation:RAII ensures resources (like memory or file handles) are acquired in a constructor and released in the destructor, preventing leaks even if exceptions occur.
Explanation:Method overriding relies on dynamic binding (runtime polymorphism) to determine which version of the method (base or derived) to execute based on the object's actual type.
Incorrect! Try again.
45In Java, does System.gc() force Garbage Collection immediately?
A.Yes, always.
B.No, it only suggests to the JVM that garbage collection is required.
C.Yes, but only for the Stack.
D.No, it creates a new memory segment.
Correct Answer: No, it only suggests to the JVM that garbage collection is required.
Explanation:The JVM decides when to run the Garbage Collector. System.gc() is a request, not a command, and the JVM may ignore it.
Incorrect! Try again.
46What is the result of int *p = (int*)malloc(sizeof(int)); if memory allocation fails?
A.Returns a dangling pointer.
B.Throws an exception.
C.Returns NULL.
D.Terminates the program immediately.
Correct Answer: Returns NULL.
Explanation:In C, malloc returns NULL if the system cannot allocate the requested memory block.
Incorrect! Try again.
47Which of the following is true about a Constructor?
A.It must have a return type of void.
B.It can be virtual.
C.It has the same name as the class and no return type.
D.It can be static.
Correct Answer: It has the same name as the class and no return type.
Explanation:Constructors initializes objects. They cannot return values (not even void), cannot be virtual, and cannot be static.
Incorrect! Try again.
48How does passing a large object by value affect memory?
A.It saves memory.
B.It consumes more stack memory due to copying.
C.It allocates memory on the heap.
D.It has no effect on memory.
Correct Answer: It consumes more stack memory due to copying.
Explanation:Pass by value creates a copy of the argument on the stack. For large objects, this copy operation consumes significant stack space and CPU time.
Incorrect! Try again.
49What is the primary role of the protected access specifier?
A.Accessible everywhere.
B.Accessible only within the class.
C.Accessible within the class and its derived classes.
D.Accessible only by friend functions.
Correct Answer: Accessible within the class and its derived classes.
Explanation:protected members are similar to private members but are also accessible to classes that inherit from the base class.
Incorrect! Try again.
50Which pointer arithmetic operation is valid?
A.Adding two pointers.
B.Multiplying a pointer by a constant.
C.Subtracting two pointers of the same type.
D.Dividing a pointer by a constant.
Correct Answer: Subtracting two pointers of the same type.
Explanation:Subtracting two pointers returns the number of elements (offset) between them. Adding, multiplying, or dividing pointers is invalid.