Which keyword is used to create a class in Python?
A object
B create
C define
D class
In Python, the class keyword is used to define a new class. A class serves as a blueprint for creating objects, encapsulating data and behavior into a single unit. It is the foundation of object-oriented programming in Python.
What is the default return type of a function in C if no type is specified?
A float
B void
C int
D char
In C, if no return type is specified in the function definition, it defaults to void, indicating that the function does not return a value. It is important to specify a valid return type, like int or float, when a value needs to be returned.
Which data type in Java is used for storing a single character?
A char
B string
C int
D boolean
In Java, the char data type is used to store a single character. It holds a 16βbit Unicode character, and each char represents a single character like ‘A’, ‘1’, or any symbol.
Which of the following is used to handle errors in Java?
A abort
B exception
C try-catch
D error
In Java, the try-catch block is used to handle exceptions (errors that occur during the execution of a program). The code inside the try block is executed, and if an error occurs, it is caught by the catch block.
What is the purpose of the break statement in a loop?
A Skip the iteration
B End the loop
C Exit the function
D Continue the loop
The break statement is used to immediately exit a loop (or switch statement). It helps to stop further iterations and exit the loop prematurely when a certain condition is met.
Which of the following is a valid way to define a list in Python?
A list = ()
B list = []
C list = <>
D list = {}
In Python, a list is defined using square brackets []. It is an ordered collection of items, and the items can be of different data types, including strings, numbers, and other lists.
What is the primary purpose of the malloc() function in C?
A Free memory
B Perform arithmetic
C Allocate dynamic memory
D Initialize a variable
In C, the malloc() function is used to allocate memory dynamically at runtime. It returns a pointer to the allocated memory, which can then be used to store data. Memory allocated with malloc() must be freed using free().
Which of these is used for conditional statements in C?
A for
B if-else
C do-while
D while
In C, the if-else statement is used for conditional logic, allowing the program to execute different blocks of code based on whether a condition evaluates to true or false.
In Java, how do you handle multiple exceptions in a single catch block?
A Use a comma
B Use if
C Use || operator
D Use | operator
In Java, to handle multiple exceptions in a single catch block, you can use the | operator to combine different exception types. This allows one catch block to handle multiple exceptions.
What is the purpose of a destructor in OOP?
A To destroy objects
B To modify objects
C To create objects
D To initialize objects
A destructor in object-oriented programming (OOP) is a special method that is called when an object is destroyed. It helps in cleaning up and releasing resources such as memory or file handles associated with the object.
Which of these is used to store key-value pairs in Python?
A Set
B Dictionary
C List
D Tuple
In Python, a dictionary is used to store data in key-value pairs. It allows fast lookups and efficient data retrieval using keys. Dictionaries are unordered and mutable, and they can hold a variety of data types.
Which operator is used to assign a value to a variable in Java?
A +
B :=
C ==
D =
In Java, the = operator is used for assignment, meaning it assigns a value to a variable. The == operator is used for comparison, checking if two values are equal.
What does the continue statement do in a loop?
A Exits the program
B Skips the current iteration
C Ends the loop
D Pauses the loop
The continue statement in a loop is used to skip the rest of the current iteration and move to the next iteration. It is useful when you want to avoid executing certain code under specific conditions.
What is the purpose of a pointer in C?
A Point to memory location
B Define a variable
C Declare a constant
D Store a value
In C, a pointer is a variable that stores the memory address of another variable. Pointers are useful for dynamic memory allocation and for working with arrays and structures in an efficient way.
Which of the following is the correct way to declare an array in C?
A arr = int[3]{1, 2, 3}
B int arr[] = {1, 2, 3}
C array int[] = {1, 2, 3}
D int[] arr = {1, 2, 3}
In C, arrays are declared by specifying the data type followed by the array name and its values inside curly braces {}. The size of the array can be omitted if the values are provided.