The int data type in C is used to represent integer values, which are whole numbers without decimal points. It is one of the most commonly used data types in C programming for numeric calculations.
In Java, which keyword is used to create a subclass?
A extends
B implements
C this
D super
In Java, the extends keyword is used to create a subclass that inherits properties and methods from a parent class. This supports inheritance in object-oriented programming, allowing code reuse and structure.
Which of the following is true about compiled languages?
A Execute line by line
B Require an interpreter
C Run slower than interpreted
D Converted to machine code
Compiled languages, such as C, are converted into machine code directly through a compiler. This allows the program to run faster because it does not require interpretation during execution, unlike scripting languages.
In Python, what does the continue statement do inside a loop?
A Exits the loop
B Breaks the loop
C Skips the current iteration
D Stops the program
The continue statement in Python is used to skip the rest of the code inside the current iteration of a loop and move to the next iteration. This is useful when certain conditions should prevent further processing in that iteration.
Which of the following is a feature of object-oriented programming?
A Compilation
B Inheritance
C Recursion
D Loops
Inheritance is a fundamental feature of object-oriented programming (OOP) where a new class derives properties and methods from an existing class. This helps in code reuse and hierarchical class organization.
In C, how do you declare a pointer?
A pointer int;
B int ptr;
C int ptr;
D ptr int;
In C, a pointer is declared by specifying the data type followed by an asterisk () and the pointer name. This indicates that the variable ptr will hold the address of an integer value.
Which of the following is a type of loop in Java?
A foreach
B repeat
C until
D do-while
The do-while loop in Java executes the block of code at least once, and then continues to repeat as long as the condition is true. This ensures that the loop runs before checking the condition.
In Python, which method is used to open a file for reading?
A open()
B load()
C fileopen()
D readfile()
In Python, the open() function is used to open a file. The mode is specified within the function, such as ‘r’ for reading. It returns a file object, which can then be used for reading or writing to the file.
Which of the following is a key feature of interpreted languages like Python?
A Line-by-line execution
B No debugging needed
C Compiled before execution
D Faster execution
Interpreted languages like Python execute code line by line, rather than compiling the entire code at once. This allows for immediate feedback and debugging but typically results in slower execution compared to compiled languages.
In C, which function is used to allocate memory dynamically for an array?
A realloc()
B free()
C calloc()
D malloc()
The malloc() function in C allocates a specified number of bytes of memory during runtime. It returns a pointer to the allocated memory, which can then be used to store data such as arrays or structures.
What is the primary purpose of using functions in programming?
A Increase execution time
B Organize code
C Simplify debugging
D Increase memory usage
Functions are used to organize code into reusable blocks. They allow a task or calculation to be performed multiple times throughout the program without duplicating code, improving maintainability and readability.
Which of the following is used to handle exceptions in Java?
A try-except
B assert
C catch
D throw
In Java, exceptions are handled using a try-catch block. Code that might throw an exception is placed inside the try block, and the catch block handles the exception if it occurs during execution.
What does the return statement do in a function?
A Prints output
B Starts the function
C Exit the function and returns a value
D Ends the program
The return statement in programming is used to exit a function and optionally pass a value back to the caller. This allows the function to return a result, which can be used elsewhere in the program.
In Java, which of these is used to read input from the user?
A Console.read()
B Scanner.next()
C BufferedReader.read()
D System.input()
In Java, the Scanner.next() method is commonly used to read input from the user. The Scanner class provides various methods to capture input such as strings, integers, and floats from the console.
What does a class represent in Object-Oriented Programming (OOP)?
A A blueprint for objects
B A data type
C A collection of data
D A function definition
In OOP, a class is a blueprint or template for creating objects. It defines the properties (attributes) and methods (functions) that the objects created from the class will have, allowing for object instantiation and encapsulation of data and behavior.