Correct Answer: A) Use array[length-1] for access
Explanation: Arrays are zero-indexed in most languages, so the last element is accessed using the index length-1
.
A) int[] arr = new int[5];
B) array int arr = 5;
C) declare int arr[5];
D) int arr = [5];
Correct Answer: A) int[] arr = new int[5];
Explanation: In Java, arrays are declared using square brackets []
, followed by the new
keyword to allocate memory for the specified size.
A) Use array[length-1] for access
B) Reference array[-1] directly
C) Access array[length*2] directly
D) Use array[0] for the last element
Correct Answer: A) Use array[length-1] for access
Explanation: Arrays are zero-indexed in most languages, so the last element is accessed using the index length-1
.
A) True as default value
B) False as default value
C) Null as default value
D) Undefined in Java memory
Correct Answer: B) False as default value
Explanation: In Java, boolean variables default to false
when not explicitly initialized, ensuring predictable behavior.
A) || operator for logic check
B) := operator for comparison
C) && operator for conditions
D) == operator for comparison
Correct Answer: D) == operator for comparison
Explanation: The ==
operator checks if two values are equal, returning True
or False
depending on the comparison.
A) condition ? value1 : value2
B) condition == value ? option
C) if(condition) {value1} else {value2}
D) option (condition) : value check
Correct Answer: A) condition ? value1 : value2
Explanation: The ternary operator is a shorthand for an if-else
statement, evaluating a condition and returning one of two values.
A) <class ‘int’> in Python
B) <class ‘str’> in Python
C) <class ‘float’> in Python
D) Error in type check
Correct Answer: C) <class ‘float’> in Python
Explanation: The type()
function in Python returns the type of the object. Since 5.0
is a floating-point number, the output is <class 'float'>
.
A) func for defining functions
B) def for defining functions
C) lambda for defining functions
D) init for defining functions
Correct Answer: B) def for defining functions
Explanation: In Python, the def
keyword is used to declare a function, followed by the function name and parameters in parentheses.
A) Hello World is displayed
B) HelloWorld is displayed
C) Error in concatenation syntax
D) Hello-World is displayed
Correct Answer: B) HelloWorld is displayed
Explanation: The +
operator concatenates strings in most languages, combining "Hello"
and "World"
into "HelloWorld"
.
A) while True: loop execution
B) for x in range(): loop execution
C) if x == 0: infinite check
D) do: condition until stop
Correct Answer: A) while True: loop execution
Explanation: A while True
loop runs indefinitely because the condition is always true unless explicitly terminated with a break
.
A) for in iteration loop
B) while for conditional loop
C) if for checking condition
D) do-while for guaranteed loop
Correct Answer: C) if for checking condition
Explanation: An if
statement is a conditional structure and not a loop, as it does not repeat execution based on conditions.
A) Avoid repetitive code blocks
B) Increase execution speed
C) Reduce memory consumption
D) Minimize number of variables
Correct Answer: A) Avoid repetitive code blocks
Explanation: Functions allow code reuse by enabling the same logic to be called multiple times, reducing redundancy and improving maintainability.
A) Variables store data values
B) Variables hold fixed data types
C) Variables always initialize memory
D) Variables allow data changes
Correct Answer: C) Variables always initialize memory
Explanation: Variables do not always initialize memory automatically; in some languages, they may hold garbage values if not explicitly initialized.
A) Dictionary data structure
B) Array for storing elements
C) Stack for managing sequences
D) Queue for ordered elements
Correct Answer: A) Dictionary data structure
Explanation: Dictionaries store data as key-value pairs, allowing quick access to values based on their associated keys.
A) True for non-zero check
B) False for zero condition
C) Error in logical syntax
D) True and False displayed
Correct Answer: B) False for zero condition
Explanation: In Python, 0
is considered False
in a boolean context, so the else
block is executed, printing "False"
.
A) Use find(list, element) check
B) Use list.has(element) check
C) Use list.contains() method
D) Use element in list check
Correct Answer: D) Use element in list check
Explanation: The in
keyword checks if an element exists in a list, returning True
if the element is found.
A) do-while checks at start; while checks end
B) while uses indices; do-while does not
C) do-while runs once; while may not
D) while needs initialization; do-while does not
Correct Answer: C) do-while runs once; while may not
Explanation: A do-while
loop executes at least once before checking the condition, whereas a while
loop checks the condition first.
A) The : operator in programming
B) The . operator in programming
C) The -> operator in functions
D) The @ operator in Python
Correct Answer: B) The . operator in programming
Explanation: The dot .
operator is used to access attributes or methods of an object in most programming languages.
A) 6 from multiplication
B) 8 from exponentiation
C) 16 from squaring twice
D) Error due to syntax
Correct Answer: B) 8 from exponentiation
Explanation: The **
operator in Python performs exponentiation, so 2 ** 3
calculates 2^3=8.
A) int() for conversion
B) parseInt() method
C) convertInt() function
D) strToInt() function
Correct Answer: A) int() for conversion
Explanation: The int()
function in Python and similar methods in other languages convert strings into integers.
A) A function calls itself
B) A function uses for loops
C) A function defines many variables
D) A function executes in reverse
Correct Answer: A) A function calls itself
Explanation: Recursion occurs when a function calls itself directly or indirectly, often used for solving complex problems with repeated subproblems.
& stay ahead of your competitors!
* Subscribe to our email newsletter to get the latest posts delivered right to your email.