Unit 4: Fundamentals of Programming Languages - Practice Quiz

CSE357 — Combinatorial Studies 50 Questions
0 Correct 0 Wrong 50 Left
0/50

1 In C++, which operator is used to access the memory address of a variable?

A.
B.
C.
D.

2 What is the primary difference between malloc() in C and new in C++?

A. Neither calls the constructor.
B. Both call the constructor.
C. new calls the constructor, malloc() does not.
D. malloc() calls the constructor, new does not.

3 In the context of Parameter Passing, what happens in Pass by Value?

A. The function can directly modify the original variable.
B. A copy of the actual parameter's value is passed to the function.
C. The address of the actual parameter is passed to the function.
D. An alias to the actual parameter is created.

4 Which storage class in C/C++ preserves the value of a local variable between function calls?

A. extern
B. register
C. auto
D. static

5 Which concept in OOP allows a class to derive properties and behavior from another class?

A. Polymorphism
B. Abstraction
C. Inheritance
D. Encapsulation

6 In Java, objects are stored in which area of memory?

A. Heap
B. Stack
C. ROM
D. Register

7 What is the result of dereferencing a NULL pointer in C++?

A. It causes a segmentation fault or undefined behavior.
B. It creates a new object.
C. It returns 0.
D. It returns a random integer.

8 Which of the following creates a Memory Leak?

A. Allocating memory on the heap and failing to free it.
B. Using a global variable.
C. Passing a pointer by reference.
D. Allocating memory on the stack.

9 What is Dynamic Binding (Late Binding)?

A. Binding variable names to memory addresses during coding.
B. Linking a function call to the code to be executed at runtime.
C. Linking a function call to the code to be executed at compile time.
D. Hardcoding function addresses.

10 In C++, what is the this pointer?

A. A const pointer that points to the object invoking the member function.
B. A global pointer accessible by all classes.
C. A pointer to the base class.
D. A pointer to the derived class.

11 Which Java keyword is used to prevent a class from being inherited?

A. final
B. const
C. abstract
D. static

12 In C, if int arr[5] = {1, 2, 3, 4, 5}; and int *p = arr;, what is the value of *(p + 2)?

A. 3
B. 1
C. 2
D. Address of 3

13 What is a Dangling Pointer?

A. A pointer that has not been initialized.
B. A pointer to a constant value.
C. A pointer pointing to a memory location that has been deleted or freed.
D. A pointer pointing to NULL.

14 Which feature of OOP describes wrapping data and methods into a single unit?

A. Encapsulation
B. Polymorphism
C. Recursion
D. Inheritance

15 In Java, parameter passing is always:

A. Pass by Name
B. Pass by Pointer
C. Pass by Value
D. Pass by Reference

16 What is the purpose of a Virtual Destructor in C++?

A. To prevent the class from being instantiated.
B. To delete objects faster.
C. To ensure the derived class destructor is called when deleting via a base class pointer.
D. To allow multiple inheritance.

17 Which area of memory is used for recursive function calls and local variables?

A. Stack
B. Heap
C. Data Segment
D. Code Segment

18 In C++, what is the size of an empty class?

A. 2 bytes
B. 0 bytes
C. 1 byte
D. 4 bytes

19 What is the default access specifier for members of a class in C++?

A. protected
B. private
C. internal
D. public

20 Which 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);

21 What implies the concept of Polymorphism?

A. Automatic memory management.
B. Hiding data implementation.
C. One interface, multiple methods.
D. Creating new classes from old ones.

22 What is the output of sizeof(char*) on a standard 64-bit architecture?

A. 1
B. 4
C. 16
D. 8

23 In Java, what mechanism handles the deallocation of memory on the Heap?

A. Destructors
B. Garbage Collector
C. delete operator
D. free() function

24 What is a Reference in C++?

A. A duplicate copy of a variable.
B. An alias for an existing variable.
C. A pointer that can be null.
D. A variable stored in the CPU register.

25 Which problem arises when two pointers point to the same memory location and one is freed?

A. Buffer Underrun
B. Dangling Pointer
C. Stack Overflow
D. Memory Leak

26 What is the Diamond Problem in C++?

A. A syntax error in template classes.
B. A memory leak in a loop.
C. Ambiguity arising from multiple inheritance where two base classes inherit from a common ancestor.
D. An issue with pointer arithmetic on 2D arrays.

27 What is a Pure Virtual Function in C++?

A. A function with no return type.
B. A function that cannot be overridden.
C. A function that does not use any variables.
D. A virtual function initialized to 0, forcing derived classes to override it.

28 In the context of parameter passing, what is an Activation Record?

A. A data structure stored on the stack containing local variables and return addresses for a function call.
B. A log of compilation errors.
C. A database of class methods.
D. A record of all heap allocations.

29 Which 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 prevents the function from modifying the argument.
D. It avoids copying large objects, improving performance.

30 In C++, int &r = x; is an example of:

A. Reference declaration
B. Pointer declaration
C. Address-of operator
D. Bitwise AND

31 What defines a Deep Copy?

A. Copying the object and allocating new memory for the data pointed to by the object.
B. Using the assignment operator =.
C. Copying only the pointer address.
D. Copying the object bit-by-bit.

32 Which operator is used to release memory allocated by new[]?

A. delete[]
B. delete
C. remove
D. free

33 Which of the following is NOT a principle of OOP?

A. Compilation
B. Encapsulation
C. Inheritance
D. Polymorphism

34 In Java, String objects are immutable. What does this mean?

A. Their values cannot be changed after creation.
B. They cannot be passed to functions.
C. They cannot be deleted.
D. They are stored in the stack only.

35 What is the difference between struct and class in C++ regarding inheritance?

A. There is no difference.
B. Structs inherit publicly by default; classes inherit privately by default.
C. Classes cannot inherit from structs.
D. Structs cannot inherit.

36 If a recursive function does not have a base case, what error occurs?

A. Compilation Error
B. Linker Error
C. Heap Overflow
D. Stack Overflow

37 What is Function Overloading?

A. Defining a function in the base and derived class with the same signature.
B. Passing too many parameters to a function.
C. Defining multiple functions with the same name but different parameters.
D. Calling a function inside itself.

38 In C++, the keyword friend allows a function to:

A. Inherit from the class.
B. Delete the class object.
C. Access private and protected members of a class.
D. Become a member of the class.

39 Which segment of memory stores global and static variables?

A. Code Segment
B. Stack
C. Heap
D. Data Segment

40 What is the outcome of void *p; in C++?

A. It declares a pointer that returns nothing.
B. It is a syntax error.
C. It declares a null pointer.
D. It declares a generic pointer that can hold the address of any data type.

41 Which of the following best describes an Abstract Class?

A. A class that has no variables.
B. A class with only static methods.
C. A class that cannot be instantiated and is meant to be subclassed.
D. A class that is hidden from other files.

42 In C++, what is the syntax to access a member of a class using a pointer to an object?

A. .
B.
C.
D.

43 What 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.

44 Which binding technique supports Method Overriding?

A. Static Binding
B. Dynamic Binding
C. Type Binding
D. Operator Binding

45 In Java, does System.gc() force Garbage Collection immediately?

A. Yes, but only for the Stack.
B. Yes, always.
C. No, it creates a new memory segment.
D. No, it only suggests to the JVM that garbage collection is required.

46 What is the result of int *p = (int*)malloc(sizeof(int)); if memory allocation fails?

A. Throws an exception.
B. Returns NULL.
C. Returns a dangling pointer.
D. Terminates the program immediately.

47 Which of the following is true about a Constructor?

A. It must have a return type of void.
B. It can be virtual.
C. It can be static.
D. It has the same name as the class and no return type.

48 How does passing a large object by value affect memory?

A. It has no effect on memory.
B. It consumes more stack memory due to copying.
C. It saves memory.
D. It allocates memory on the heap.

49 What is the primary role of the protected access specifier?

A. Accessible everywhere.
B. Accessible only within the class.
C. Accessible only by friend functions.
D. Accessible within the class and its derived classes.

50 Which pointer arithmetic operation is valid?

A. Multiplying a pointer by a constant.
B. Subtracting two pointers of the same type.
C. Adding two pointers.
D. Dividing a pointer by a constant.