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. Compiler error: String and StringBuffer objects cannot be compared

  2. ClassCastException: String and StringBuffer objects cannot be compared

  3. Prints "true"

  4. Prints "false"

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

The equals method in the String class checks if the compared object is an instance of String. Since sb is a StringBuffer, the comparison immediately returns false without comparing their character contents.

Multiple choice technology programming languages
  1. It will print - false, true, false

  2. It will print - true, true, false

  3. It will print - false, false, false

  4. It will print - true, false, false

  5. Compilation error

  6. ClassCastException at runtime

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

b.equals(str) is false because Boolean.equals() returns false when comparing to a String. str.equals(buff) is false because String.equals() returns false when comparing to StringBuffer. buff.equals(b) is false because StringBuffer doesn't override equals() to compare with Boolean. Result: 'true, false, false'.

Multiple choice technology programming languages
  1. Compiler error

  2. An exception is thrown at runtime

  3. Prints [She, sells, sea, shells]

  4. Prints [he, ells, ea, hells]

  5. Prints []

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

The split("\\s") method splits the string around matches of the regular expression \s (whitespace). This correctly splits "She sells sea shells" into an array of four words, which Arrays.toString() prints as [She, sells, sea, shells].

Multiple choice technology programming languages
  1. Will not compile

  2. Will compile without error but not run

  3. Will compile with warnings but run ok

  4. Will compile with warnings, but not run

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

The code compiles with a warning because main() has no explicit return type (assumed int in pre-C99 standards). The printf statement is valid and the program runs correctly, printing "hello world" to stdout. Modern compilers may warn about implicit int declaration or missing return statement, but these are warnings, not errors.

Multiple choice technology programming languages
  1. Will not compile

  2. Will compile with warning, and run

  3. Will compile but not run

  4. Will provide an output 1

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

This code fails to compile because the #include directive is missing the closing angle bracket. The correct syntax is #include with both < and > brackets. This syntax error prevents compilation entirely. Additionally, conio.h and string.h are non-standard/unnecessary but the missing bracket is the definitive compilation error.

Multiple choice technology programming languages
  1. True

  2. False

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

The inner loop condition j=i; j&lt;=0; j-- is problematic. When i=0, j starts at 0, condition is true, j becomes -1, condition fails immediately. When i=1 or higher, j starts >=1, condition j<=0 is false immediately, so the inner loop never executes. The code runs and terminates normally - it does NOT enter an infinite loop. The claimed answer is correct.

Multiple choice technology programming languages
  1. True

  2. False

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

The outer loop runs i from 0 to 5 (inclusive). The inner loop runs j from 0 to i (exclusive), printing '1\t' each time. For i=0: prints nothing. For i=1: prints one '1'. For i=2: prints two '1's. For i=3: prints three '1's. For i=4: prints four '1's. For i=5: prints five '1's. The output matches the stated pattern of increasing 1s from 1 to 5 per row.

Multiple choice technology programming languages
  1. Will not compile

  2. Will compile without error or warning and run ok

  3. Will compile without error or warning but not run

  4. Will compile with warning but run ok

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

In modern C standards, omitting the return type of main defaults to int, and omitting a return statement at the end of main is allowed. However, in older compilers, this code compiles with a warning about the missing return type but still runs successfully.

Multiple choice technology programming languages
  1. Does not compile saying binary operator has invalid use

  2. 2.0

  3. 2.5

  4. exception will be thrown

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

The expression evaluates as: pre-decrement --i changes i from 5 to 4, then 4/2.0 gives 2.0 (double division because 2.0 is double), and the unary + keeps it as 2.0. Note: The assignment 'int a = 2.0' would cause a compilation error due to type mismatch; the question focuses on the expression value.

Multiple choice technology web technology
  1. t t1

  2. t1 t

  3. t t

  4. Compilation succeed but Runtime Exception

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

Setting thread priority to -3 throws IllegalArgumentException because Thread priority must be between MIN_PRIORITY (1) and MAX_PRIORITY (10). The code compiles successfully but fails at runtime when t1.setPriority(-3) executes. Thread priorities range from 1-10 only; values outside this range cause runtime exceptions.

Multiple choice technology web technology
  1. good

  2. Compilation succeed but Runtime Exception

  3. null

  4. Compilation fails with an error at line 5

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

The code creates a Thread with Runnable object A, names it 'good', and starts it. The run() method prints the current thread's name using Thread.currentThread().getName(), which returns 'good' since we explicitly set it with t.setName(). No compilation or runtime errors occur.

Multiple choice technology web technology
  1. false

  2. Compile Error - can't use Boolean object in if().

  3. true

  4. Compile Properly but Runtime Exception.

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

Java allows Boolean objects in if() statements due to autounboxing. The Boolean object 'expr' with value true autounboxes to primitive true, so the condition is satisfied and 'true' is printed. This is valid Java syntax - no compilation or runtime error occurs.