Computer Knowledge

Programming Output Evaluation

1,953 Questions

Programming output evaluation tests the ability to trace code execution in languages like C, Java, and SAS. It focuses on arrays, loops, pointers, and data type conversions. These technical questions are standard in computer knowledge sections for IT officer and bank exams.

Java string bufferC language pointersLoop execution outputsData type conversionsMacro variable evaluation

Programming Output Evaluation Questions

Multiple choice technology web technology
  1. Compile Properly but Runtime Exception

  2. Compile time error, because you have to do int total = ((Integer)(list.get(0))).intValue();

  3. 59

  4. Compile time error, because can't add primitive type in List.

Reveal answer Fill a bubble to check yourself
C Correct answer
Explanation

Java autoboxes the primitive int 59 to Integer when added to the ArrayList. Then get(0) returns the Integer object, which autounboxes to int when assigned to the primitive variable 'total'. The code compiles and runs successfully, outputting 59. No explicit casting or type conversion is needed thanks to autoboxing/autounboxing.

Multiple choice technology web technology
  1. NullPointerException

  2. 0

  3. Complie with Error

  4. Null

Reveal answer Fill a bubble to check yourself
A Correct answer
Explanation

When unboxing a null Integer reference to a primitive int, Java throws NullPointerException at runtime. The code compiles successfully because the assignment is syntactically valid - the error occurs during execution when the JVM tries to extract the int value from null.

Multiple choice technology programming languages
  1. 9.9

  2. 9

  3. 9.0

  4. None of the above

Reveal answer Fill a bubble to check yourself
C Correct answer
Explanation

Since a = 5, the condition (a < 5) is false, so the ternary operator returns the second operand 9. However, the ternary has operands 9.9 (double) and 9 (int), so the result type is double due to numeric promotion. The integer 9 is promoted to 9.0, and the output is 'Value is - 9.0'. Option C is correct.

Multiple choice technology programming languages
  1. The code won't compile

  2. Some things are true in this world

  3. Hey this won't compile

  4. none of the above

Reveal answer Fill a bubble to check yourself
D Correct answer
Explanation

The code is a nested if-else structure. 'if (a == true)' is true. Then it checks 'if (b == true)', which is false. This triggers the 'else if (a && (b = c))' on line 8. Since 'a' is true and the assignment '(b = c)' evaluates to true, it prints 'It's too confusing to tell'. Since this is not an option, 'none of the above' is correct.

Multiple choice technology programming languages
  1. 1

  2. Error anar is referenced before it is initialized.

  3. 2

  4. Error: size of array must be defined.

Reveal answer Fill a bubble to check yourself
C Correct answer
Explanation

The array anar is initialized with elements {1, 2, 3}. Since Java arrays use zero-based indexing, anar[1] refers to the second element, which is 2.

Multiple choice technology programming languages
  1. System.out.println( -1 >>> 2);will output a result larger than 10

  2. System.out.println( -1 >>> 2); will output a positive number

  3. System.out.println( 2 >> 1); will output the number 1

  4. System.out.println( 1 <<< 2); will output the number 4

Reveal answer Fill a bubble to check yourself
A,B,C Correct answer
Explanation

-1 >>> 2 (unsigned right shift) produces a large positive number because -1 is all 1s in binary. The result 1073741823 is larger than 10. 2 >> 1 equals 1 (right shift halves it). <<< is not a valid Java operator.

Multiple choice technology programming languages
  1. Compiler Error

  2. Compiles and runs

  3. Runtime Error

  4. None of these

Reveal answer Fill a bubble to check yourself
B Correct answer
Explanation

In Java, floating-point division by zero produces Infinity (positive or negative) rather than a runtime error. The code compiles successfully and executes without throwing an exception. Division by zero only throws ArithmeticException for integer types (int, long), not floating-point types (float, double).

Multiple choice technology programming languages
  1. The code will fail at line 1 because a hash cannot contain both numeric and string data.

  2. The code will execute without error but will output nothing.

  3. The code will output the following: 32oz 16oz 8oz

  4. The code will output the following: large medium small

Reveal answer Fill a bubble to check yourself
C Correct answer
Explanation

The keys of %hash are sorted alphabetically: 'large', 'medium', 'small'. The loop iterates through these keys and prints their corresponding values: hash{large} (32oz), hash{medium} (16oz), and hash{small} (8oz), resulting in '32oz 16oz 8oz'.

Multiple choice technology programming languages
  1. W

  2. X

  3. Y

  4. Z

Reveal answer Fill a bubble to check yourself
D Correct answer
Explanation

The sort function arranges the array elements alphabetically to ('W','X','Y'). The unshift function adds 'Z' at the beginning of the array, making it ('Z','W','X','Y'). Printing $array[0] outputs 'Z', the first element after unshift adds it to the front.

Multiple choice technology programming languages
  1. The code will output the following: Masami 10 11 12 13

  2. The code will output the following: 10 Masami 10 11 12 13

  3. The code will output the following: 10 Masami 11 12 13 Niklas

  4. The code will output the following: Masami 10 11 12 13 Niklas

Reveal answer Fill a bubble to check yourself
A Correct answer
Explanation

The array @array is constructed as (10, 'Masami', 10, 11, 12, 13, 'Niklas') because 10..13 expands to (10,11,12,13). The for loop runs from i=1 to i < $#array (which is 6), so it iterates i=1,2,3,4,5. This prints elements at indices 1 through 5: 'Masami', 10, 11, 12, 13.

Multiple choice technology programming languages
  1. The code will output the following: 11 12 13 14 15 16 17 18 19

  2. The code will output the following: 10 11 12 13 14 16 18 20 22

  3. The code will output the following: 10 11 12 13 14 16 18 20

  4. The code will output the following: 10 11 12 13 14 15 16 17 18 19 20

Reveal answer Fill a bubble to check yourself
B Correct answer
Explanation

The loop starts with $x = 10. For values 10 to 13, the else block increments $x by 1. When $x reaches 14, the if condition is met, $x is incremented by 2 to 16, and redo restarts the loop without re-evaluating the condition, printing 16, then 18, then 20.