Fundamentals of Programming MCQs (Part-5)

What is the purpose of a function in programming?

A Store data
B Declare variables
C Define constants
D Perform an action

Which of the following is a method to prevent memory leaks in C?

A Use free()
B Avoid pointers
C Use sizeof()
D Use malloc()

In Java, which of these is the correct way to declare a class?

A class ClassName {}
B object ClassName {}
C define ClassName {}
D class ClassName[] {}

What does recursion in programming mean?

A Calling a function from within itself
B Reusing code
C Returning from a function
D Repeating a task

Which of these is used to define a constant in C?

A final
B define
C immutable
D const

How do you declare a class variable in Python?

A def name
B self.name
C var name
D class name

Which of the following is a characteristic of object-oriented programming?

A Functions
B Variables
C Loops
D Classes

In Python, how is memory managed automatically?

A Using manual pointers
B Through garbage collection
C With free()
D With malloc()

What is the purpose of the new keyword in Java?

A Allocate memory for objects
B Define constants
C Assign values
D Declare a variable

Which of the following is a function used to get the length of a string in C?

A strsize()
B length()
C size()
D strlen()

What does this keyword refer to in Java?

A Parent class
B Static method
C Current object
D Previous object

Which of the following is an example of dynamic memory allocation in C?

A double x = 5
B int* arr = malloc(10 * sizeof(int))
C int arr[10];
D char str[20];

What does the super() function do in Java?

A Ends the program
B Creates a new instance
C Defines a class variable
D Calls a parent class constructor

Which operator is used for logical OR in C?

A ==
B &&
C |
D &

What is the role of the main() function in C?

A Handle errors
B Start program execution
C Declare variables
D Initialize memory