Fundamentals of Programming MCQs (Part-7)

In C, which function is used to handle memory allocation dynamically?

A malloc()
B free()
C calloc()
D sizeof()

Which of these is an example of a data structure in programming?

A function
B method
C array
D loop

What does exception handling allow you to do in a program?

A Handle errors during runtime
B Perform conditional checks
C Loop through values
D Allocate memory dynamically

How do you define a class in Java?

A class ClassName {}
B def ClassName {}
C class(ClassName)
D new ClassName()

In Python, what does the finally block do in exception handling?

A Catches errors
B Defines exceptions
C Ensures code execution
D Raises an error

In C, how do you allocate memory for an array of 10 integers dynamically?

A int* arr = malloc(10);
B int arr[10];
C int* arr = calloc(10);
D int* arr = malloc(10 * sizeof(int));

In Java, what does the super() keyword do?

A Accesses class variables
B Calls a superclass constructor
C Creates a new object
D Returns a value

What is the output of the following Python code: print(“123” + “456”)?

A 579
B None
C 123456
D TypeError

In C, what is returned by the sizeof() function?

A Size of data type
B Memory address
C Length of array
D Value of variable

What is the main advantage of using dynamic memory allocation in C?

A Faster execution
B Requires no cleanup
C No need to define array size
D Reduces code size

In Python, what does the except keyword do in exception handling?

A Raises exceptions
B Defines exceptions
C Catches and ignores exceptions
D Catches exceptions

In Java, which of the following is the correct way to catch an exception?

A try {catch}
B throw (Exception e)
C catch Exception e {}
D try-catch()

What is the result of accessing an array element out of bounds in C?

A Undefined behavior
B Syntax error
C Program crash
D Value 0

In C, what is the default value of a pointer before it is initialized?

A NULL
B Garbage value
C 0
D false

Which of these is a dynamic memory allocation function in C that initializes memory to zero?

A malloc()
B free()
C realloc()
D calloc()