Computer Knowledge

Programming Output Evaluation

1,721 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. true

  2. false

  3. compilation fails at line 21

  4. compilation fails at line 22

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

Integer values between -128 and 127 are cached by Java's Integer class, so i1 == i2 returns true for small values like 100 (same object reference). For values like 1000, outside the cached range, new Integer objects are created, so i1 and i2 reference different objects, making == return false. This tests understanding of Integer caching and reference vs value comparison.

Multiple choice technology programming languages
  1. NullPointerException

  2. Compilation fails

  3. 0

  4. 1

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

args is the command-line arguments array. When running 'java A' with no arguments, args is an empty array (length 0), not null. The code correctly accesses args.length without null checks. This tests understanding that args.length is 0 for no arguments, and that an empty array is not null.

Multiple choice technology programming languages
  1. -345678-

  2. -3--4--5--6--7--8-

  3. -3--34--345--3456--34567--345678-

  4. -345678--345678--345678--345678--345678--345678--345678-

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

The regular expression \d+ matches one or more consecutive digits. The input string '345678' consists entirely of digits, so m.find() matches the entire string as a single group. The loop runs once, printing '-345678-'.

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

  2. Hello---HelloWorld

  3. HelloWorld---Hello

  4. HelloWorld---HelloWorld

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

String objects are immutable in Java. The concat() method returns a new String object but does not modify the original. Since s1.concat() is not assigned to any variable, s1 still points to Hello, and s2 also points to Hello.

Multiple choice technology programming languages
  1. Varargs

  2. Normal

  3. Compilation Fails

  4. Runtime Exception

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

In Java, compiler resolution favors specific parameter matching over variable arity (varargs) methods. Since add(int, int) is an exact match for the arguments (9, 9), it is chosen over the varargs option, resulting in the output 'Normal'.

Multiple choice technology web technology
  1. Infinity

  2. NaN

  3. number

  4. null

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

The expression typeof 1/0 is parsed as (typeof 1) / 0 due to operator precedence. The typeof operator returns the string "number" for the value 1. Then JavaScript attempts to divide this string by 0, which coerces "number" to NaN (since it's not a valid numeric string). Finally, NaN / 0 evaluates to NaN. This is different from simply evaluating 1/0, which would give Infinity.

Multiple choice technology
  1. Something

  2. 1

  3. Error

  4. No output

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

The break statement immediately exits the while loop before Write-Host executes. The condition ($a -eq 1) is never true because $a is a string 'something', not the integer 1, so continue is never reached. The break executes on the first iteration, terminating the loop without any output.

Multiple choice technology programming languages
  1. myprog

  2. good

  3. morning

  4. Exception raised: "java.lang.ArrayIndexOutOfBoundsException: 2"

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

When Java is invoked with 'java myprog good morning', the command-line arguments array argv[] contains only [good, morning], with indices 0 and 1. Accessing argv[2] attempts to read beyond the array bounds, causing an ArrayIndexOutOfBoundsException. The program name 'myprog' is not in the argv array.

Multiple choice technology programming languages
  1. one

  2. one default

  3. one two default

  4. default

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

In Java switch statements, execution falls through to the next case when a break statement is missing. Since i=1 matches case 1, it prints 'one', then continues to case 2 printing 'two', then to default printing 'default'. Without break statements after each case, all subsequent code executes.

Multiple choice technology programming languages
  1. System.out.println(Math.floor(-4.7));

  2. System.out.println(Math.round(-4.7));

  3. System.out.println(Math.ceil(-4.7));

  4. System.out.println(Math.min(-4.7));

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

Math.ceil returns the smallest integer greater than or equal to its argument. For -4.7, ceiling gives -4.0 (since -4 is greater than -4.7). Math.floor would give -5.0, Math.round would give -5 (rounds toward positive infinity for negative numbers), and Math.min requires two arguments.

Multiple choice technology programming languages
  1. float f=2.3;

  2. char c="z";

  3. boolean b=null;

  4. int i=21;

  5. byte b=257;

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

int i=21; is a valid declaration and compiles successfully. float f=2.3; fails because 2.3 is a double literal. char c="z"; fails because double quotes are for Strings, not chars. boolean b=null; is invalid because boolean is a primitive, and byte b=257; exceeds byte's range.