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. 23

  2. Garbage Value

  3. 0

  4. Compilation-Array out of boundary

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

In the C language, compiler specifications do not enforce array boundary checks. Writing to a[7] translates to modifying the memory offset corresponding to that index, and subsequently printing it retrieves the assigned value of 23 without causing a compilation or runtime error.

Multiple choice technology programming languages
  1. i = 3

  2. Compilation fails.

  3. A ClassCastException is thrown at line 6.

  4. A ClassCastException is thrown at line 7.

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

The code compiles and runs successfully. A Foo object is created, upcast to Object type, then downcast back to Foo. Since the actual object is a Foo instance, the downcast succeeds and foo.i is accessible, printing 'i = 3'. This is a valid casting pattern in Java.

Multiple choice technology programming languages
  1. i = 6 and j = 5

  2. i = 5 and j = 6

  3. i = 5 and j = 5

  4. i = 6 and j = 6

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

The do-while loop runs while i < 5. In each iteration, i increments (postfix) and j decrements (prefix). After 4 iterations, i becomes 5 (causing loop exit) and j becomes 6. The continue statement has no effect since it's at the end of the loop body.

Multiple choice technology programming languages
  1. i = 6 and j = 5

  2. i = 5 and j = 5

  3. i = 5 and j = 6

  4. i = 6 and j = 4

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

In the do-while loop, j decrements each iteration. When i increments to 5 (via ++i in the while condition check), ++i < 5 becomes 5 < 5 (false), terminating the loop. At this point, j has decremented four times from 10 to 6, yielding i = 5 and j = 6.

Multiple choice technology programming languages
  1. x = 1

  2. x = 3

  3. Compilation fails.

  4. An exception is thrown at runtime.

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

The code in line 13 uses assignment (=) instead of equality comparison (==). In Java, the if condition requires a boolean expression, but x = y results in an integer value, which cannot be converted to boolean. This causes a compilation error.

Multiple choice technology programming languages
  1. Compilation fails because of an error in line 2 of class Test2.

  2. x = 42

  3. Compilation fails because of an error in line 3 of class Test1.

  4. Compilation fails because of an error in line 4 of class Test2.

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

The compilation fails in Test2 (line 2) because the class extends 'test1.Test1' but this package reference is not imported. To use a class from another package, you need to import it first: 'import test1.Test1;'. Line 2 of Test2 is where Test1 is referenced without an import statement.

Multiple choice technology programming languages
  1. ABDCBDCB

  2. ABCDABCD

  3. Compilation fails.

  4. An exception is thrown at runtime.

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

First, the loop initialization runs foo('A') (prints A). In the first check, foo('B') (prints B) and i<2 are true; loop body increments i and runs foo('D') (prints D); then update runs foo('C') (prints C). This repeats until the third check where i<2 is false, terminating after printing B.

Multiple choice technology operating systems
  1. It will get printed once

  2. it will get printed 8times

  3. it will not work

  4. It wil print three times

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

Each fork() call doubles the number of processes. Starting with 1 process, after three consecutive fork() calls: 1 → 2 → 4 → 8 processes total. All 8 processes execute the printf statement, so the output appears 8 times. This is a classic example of exponential process creation in Unix systems.

Multiple choice technology platforms and products
  1. final String abc = "Neeraj"; abc = "Rathi";

  2. final String abc;abc = "Rathi";

  3. final ArrayList al = new ArrayList();al.add("Neeraj");al.add("Rathi");

  4. final int i; i = 0;

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

A final variable can only be assigned once. In option A, abc is declared final and initialized with 'Neeraj', then reassigned to 'Rathi' - this is illegal. Options B and D are legal blank finals (declared final, assigned once later). Option C works because the reference is final, not the contents - you can modify the list but not reassign al.

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

  2. OF(11) is: 56

  3. Compilation fails.

  4. Runtime Exception

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

The code contains a syntax error on the else clause. The statement 'else (x <= 4)' is invalid Java syntax - an else statement cannot have a condition. It should be 'else if (x <= 4)' for conditional execution. This causes the code to fail compilation.

Multiple choice technology programming languages
  1. -f and java.ArrayIndexOutOfBoundsException

  2. -f

  3. ArrayIndexOutOfBoundsException

  4. None of these.

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

When 'java Demo' is run with no command-line arguments, args[0] throws ArrayIndexOutOfBoundsException immediately. This is caught by the catch(Exception x) block, setting s='b'. The finally block executes regardless, appending 'f' to s. The output is '-f' followed by the ArrayIndexOutOfBoundsException being printed (since it wasn't caught specifically). The initial try block's 't' is never reached.

Multiple choice technology programming languages
  1. int y = x;

  2. int y = 10;

  3. int y = 11;

  4. None of the above will allow compilation to succeed.

  5. int y = 12;

  6. int y = 13;

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

The do-while loop executes the body first, then checks the condition x++ < y. With y=11 and x starting at 0: x increments to 1 and 1<11 is true (loop continues). This continues until x becomes 11: x increments to 12 and 12<11 is false (loop exits). At exit, x=12, which is printed. Each iteration increments x after the comparison.

Multiple choice technology programming languages
  1. -

  2. -c

  3. -c2

  4. -2c

  5. -c22b

  6. Compilation fails.

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

method1 calls method2, which calls method3 (first call). method3 throws Exception immediately. This exception propagates to method1's catch block, appending 'c' to s. The code 's += 2' and everything after in method2 never executes (unreachable after exception). The initial s='-' becomes '-c'.

Multiple choice technology programming languages
  1. -c

  2. -X

  3. -cm

  4. -cmp

  5. -cmXp

  6. Compilation fails.

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

The switch statement has no break statements, causing fall-through. With TimeZone.CST: case CST matches, appends 'c'. No break, so falls through to case MST, appends 'm'. No break, falls through to default, appends 'X'. No break, falls through to PST, appends 'p'. The final string is '-cmXp'. Fall-through continues through all cases after the match.