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 programming languages
  1. 8

  2. 8 7

  3. 8 7 6

  4. Compilation fails.

  5. An exception is thrown at runtime.

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

The code fails to compile for multiple reasons. First, there is a syntax error in the print statement, which ends with a closing brace instead of a parenthesis. Second, the continue statement attempts to target an if statement label instead of a loop, which is illegal in Java.

Multiple choice technology programming languages
  1. //1 will create an compilation error

  2. //2 will create an compilation error

  3. //1 and //2 both will create an compilation error

  4. //1 will create an runtime error

  5. //2 will create an runtime error

  6. //1 and //2 both will create an runtime error

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

Both statements are invalid. 'i++=i++' and '++i=++i' both attempt to assign to the result of an increment operation. In Java, increment expressions (i++ or ++i) return values but cannot be assignment targets (not l-values). Both lines cause compilation errors. The error is not at runtime but during compilation.

Multiple choice technology programming languages
  1. for(int y : x) {

  2. for(x : Int y) {

  3. int y = 0; for(y : x) {

  4. for(int y=0, z=0; z<x.length; z++) { y = x[z];

  5. for(int y=0, int z=0, int z=0; z<x.length; z++) { y = x[z];

  6. int y = 0; for(int z=0; z<x.length; z++) { y = x[z];

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

Option A is the enhanced for loop syntax - correct. Option F declares y before the loop and uses traditional for loop to iterate - correct. Options B, C, D, E have syntax errors: wrong order in B, wrong syntax in C, incorrect declaration in E (int z declared twice in for-init). Only A and F compile independently.

Multiple choice technology programming languages
  1. abc

  2. abcde

  3. Compilation fails due only to an error on line 7.

  4. Compilation fails due to errors on multiple lines.

  5. Compilation fails due only to an error on line 10.

  6. Compilation fails due only to an error on line 11.

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

Line 11 fails compilation. In switch statements, case labels must be compile-time constant expressions. x4 is a final Integer (wrapper), not a compile-time constant. Only constant primitive types or String are allowed. x2 works (int primitive), x4 fails (Integer object). The error is specifically on line 11.

Multiple choice technology programming languages
  1. -ic of

  2. -mf of

  3. Compilation failure

  4. -ic mf of

  5. -ic mc mf of

  6. -ic mc of mf

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

The nested try-catch-finally blocks execute in sequence: Inner try throws, caught by 'ex' -> 'ic' appended. Then throws new Exception, caught by outer catch 'x' -> 'mc' appended. Outer finally executes -> 'mf' appended. Outermost finally executes -> 'of' appended. The sequence is ic (inner catch), mc (middle catch), mf (middle finally), of (outer finally) = '-ic mc mf of'.

Multiple choice technology programming languages
  1. null

  2. null null

  3. A ClassCastException is thrown.

  4. A NullPointerException is thrown.

  5. A NoClassDefFoundError is thrown.

  6. An ArrayIndexOutOfBoundsException is thrown.

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

The command 'java Miner.java' makes args[0] = 'Miner.java' (not empty). The array has Mineral and Gem objects. Both are cast to Mineral successfully (Gem extends Mineral). getWeight prints 'null ' (static String s is null) twice. No division by zero occurs (x=7, not 0). The output is 'null null'. args[0] exists, so no ArrayIndexOutOfBoundsException.

Multiple choice technology programming languages
  1. Compilation error.

  2. Runtime error.

  3. Hello Hi Hi_Hello Hi

  4. Hi_Hello

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

The code has two overloaded main methods. When main(String[]) runs, it prints "Hello" then calls main(int[]) which prints "Hi" and returns. In the main class, ob.main(b) prints "Hello" then "Hi", then "Hi_Hello" prints, then main(a) prints "Hi" again. Total output: Hello Hi Hi_Hello Hi. Options A and B are wrong because the code compiles and runs without errors. Option D only captures part of the output.

Multiple choice technology programming languages
  1. Hello....

  2. Hi....

  3. Compilation error

  4. Runtime error

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

Java uses string literal pooling. When s1 and s2 are both assigned "Hello", they reference the same string literal object in the pool. The == operator compares references, not content. Since both variables point to the same pooled string, s1 == s2 returns true, printing "Hello....". Option B is wrong because the references are equal. Options C and D are incorrect as the code compiles and runs normally.

Multiple choice technology programming languages
  1. OF(11) is: 45

  2. OF(11) is: 56

  3. OF(11) is: 89

  4. OF(11) is: 111

  5. Compilation fails.

  6. Runtime Exception

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

The code contains a syntax error: 'else (x <= 4)' is invalid Java syntax. An else clause cannot have a condition - it should be 'else if (x <= 4)'. This compilation error prevents the code from running, so none of the numeric outputs can be produced. Options A-D are all numeric results that would require successful compilation and execution.

Multiple choice technology databases
  1. 1

  2. 2

  3. 3

  4. 0

  5. None of the above

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

The variable l_child_number is declared in the inner DECLARE block with scope limited to that block. When DBMS_OUTPUT.PUT_LINE in the outer block tries to access l_child_number, the variable is out of scope, causing an exception. The WHEN OTHERS exception handler sets l_child_number to 0, so the output is 0. This tests understanding of PL/SQL variable scope.

Multiple choice technology programming languages
  1. empty string

  2. 20

  3. 0

  4. error

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

The code copies string 'name' to dynamically allocated memory with memset. However, the while loop increments p2 after copying the null terminator. After copying ends, p2 points to the null terminator byte, not the start of the copied string. When printf prints from p2, it prints an empty string since p2 now points to the null character.

Multiple choice technology programming languages
  1. Two lines with “Cisco Systems” will be printed.

  2. Compile error

  3. run time error

  4. Cisco Systemsn

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

The code has an if statement that only affects the first printf call. The second printf is outside the if block, so it executes regardless of the condition. Since if(a==0) is true, the first printf executes and prints 'Cisco Systems', then the second printf also executes and prints another line with 'Cisco Systems', resulting in two identical lines.