In C, the multiplication operator (*) has higher precedence than addition (+). Thus, the expression 5 + 3 * 2 is evaluated as 5 + (3 * 2) which equals 5 + 6 = 11.
What type of loop guarantees at least one execution in C?
A if
B while
C for
D do-while
The do-while loop guarantees at least one execution of the code block, as the condition is checked after the execution of the loop’s body. This ensures the loop runs at least once regardless of the condition.
Which keyword is used to define a function in Python?
A func
B def
C define
D function
In Python, the def keyword is used to define a function. It is followed by the function name and parentheses, and the functionโs body is indented beneath it. The def keyword indicates a function declaration.
Which operator in Java is used for division?
A /
B *
C //
D &
In Java, the / operator is used for division. It performs division on numeric types and returns the quotient of the division. If both operands are integers, the result will also be an integer (floor division).
Which type of error occurs during runtime?
A Compilation error
B Runtime error
C Logical error
D Syntax error
A runtime error occurs when the program is running. It usually happens due to invalid operations such as dividing by zero or trying to access an array element out of bounds, causing the program to crash or behave unexpectedly.
What does the && operator do in C?
A Compares values
B Assigns values
C Checks equality
D Logical AND
The && operator in C is a logical AND operator used to evaluate two expressions. It returns true (1) only if both expressions are true. If either expression is false, it returns false (0).
Which of these statements is used to exit a loop in Python?
A stop
B exit
C break
D continue
In Python, the break statement is used to exit a loop prematurely. It immediately terminates the loop, and the program continues executing the code after the loop.
Which data type in Java is used to store boolean values?
A char
B boolean
C int
D bool
In Java, the boolean data type is used to store two possible values: true or false. It is typically used for conditional logic and controlling the flow of execution in the program.
What is the output of print(“Hello”[1]) in Python?
A l
B H
C o
D e
In Python, strings are indexed starting from 0. Therefore, “Hello”[1] refers to the second character in the string, which is e. The index is 1-based, and each character can be accessed individually.
Which of these keywords is used for creating a constant in Java?
A final
B immutable
C constant
D static
In Java, the final keyword is used to define constants. Once a variable is declared as final, its value cannot be changed throughout the program, effectively making it a constant.
What does sizeof() return in C?
A Length of array
B Size of data
C Memory address
D Size of variable
The sizeof() operator in C returns the size (in bytes) of the data type or variable. It helps in memory management by determining how much space is required to store a particular data type or object.
Which data type is used for decimals in Java?
A float
B int
C char
D double
In Java, the double data type is used to store decimal numbers with double precision. It allows for the representation of real numbers with a higher degree of accuracy compared to float.
What is the correct syntax to create a method in Java?
A function methodName()
B void methodName()
C def methodName()
D method methodName()
In Java, a method is defined with a return type (such as void for no return value), followed by the method name and parentheses. The body of the method contains the statements that define its functionality.
Which of these is used to handle exceptions in Python?
A try-finally
B try-except
C handle-error
D try-catch
In Python, the try-except block is used for exception handling. Code that might raise an exception is placed inside the try block, and the except block handles the exception if it occurs.
What is the correct way to declare an integer array in C?
A int arr[]
B arr int[]
C int[] arr
D arr int[10]
In C, arrays are declared by specifying the data type followed by the array name and square brackets. Option int arr[]; is a valid declaration, though the size can also be specified if needed.