The if statement is used to test a condition in programming. If the condition evaluates to true, the code inside the if block is executed. It is a fundamental control structure for decision-making in programming.
In C, which data type is used to represent a single character?
A string
B char
C int
D float
The char data type in C is used to store a single character. It takes 1 byte of memory and can store any character from the ASCII table, such as ‘a’, ‘1’, or any special character.
Which of the following is used to declare a function in C?
A function_name()
B def
C function
D void
In C, the void keyword is used when a function does not return any value. For example, void function_name() declares a function that does not return any data after execution.
What is the purpose of break in loops?
A Restarts the loop
B Exits the loop
C Skips the iteration
D Continues the loop
The break statement is used to immediately exit from a loop. It is useful for breaking out of for, while, or do-while loops when a specific condition is met, such as finding the desired element in a search.
In Python, how do you check if a variable is of a specific type?
A type()
B instance()
C check()
D is()
The type() function in Python is used to check the type of a variable. For example, type(variable) will return the type of variable, such as int, str, list, etc.
Which operator is used to perform division in Python?
A %
B //
C *
D /
The / operator in Python is used to perform division. It returns the result as a floating-point number, even if both operands are integers. For integer division (discarding the decimal), the // operator is used.
In Java, which of the following is used to handle multiple exceptions in a try block?
A throws
B catch
C throw
D finally
In Java, catch is used to handle exceptions thrown by code inside the try block. Multiple catch blocks can be used to handle different types of exceptions, making error handling more robust.
What is a pointer in C?
A A memory address holder
B A variable
C A reference
D A data type
A pointer in C is a variable that holds the memory address of another variable. Pointers are essential for dynamic memory allocation and manipulation of arrays, structures, and function arguments by reference.
What does the sizeof() operator do in C?
A Returns data type
B Allocates memory
C Returns size in bytes
D Returns memory address
The sizeof() operator in C returns the size of a variable or data type in bytes. It is often used to determine memory requirements for variables and data structures in the program.
Which of these is a valid array declaration in C?
A int[] arr = {}
B int arr[10];
C array int[10];
D int arr[]
In C, an array is declared by specifying the data type, followed by the array name and the size of the array. For example, int arr[10]; declares an integer array with 10 elements.
In Java, what does the new keyword do?
A Initializes a method
B Creates a new class
C Creates a function
D Allocates memory for an object
The new keyword in Java is used to allocate memory for an object and call the constructor of the class. It creates an instance of the class on the heap, allowing access to its properties and methods.
Which of the following is used to define a string in Python?
A ()
B “”
C string()
D []
In Python, strings can be defined using single or double quotes, such as “Hello” or ‘Hello’. Both are valid ways to represent text data in Python, and the choice depends on the programmer’s preference.
In C, which of the following functions is used to open a file?
A fileopen()
B open()
C file()
D fopen()
In C, fopen() is used to open a file. It takes two parameters: the file name and the mode in which to open the file (e.g., “r” for read, “w” for write). It returns a pointer to the file stream.
What is the primary purpose of the main() method in Java?
A Initialize variables
B Handle exceptions
C Serve as the entry point
D Define a class
In Java, the main() method is the entry point for any standalone Java application. It is the method that the JVM calls when starting the program, and it typically contains the code to initialize and start execution.
In Python, which of the following is used to terminate a loop early?
A break
B return
C continue
D exit
The break statement in Python is used to terminate a loop early. It stops the loop’s execution and transfers control to the next statement after the loop. It is commonly used to exit a loop when a condition is met.