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 general knowledge science & technology
  1. float f = 1.3;

  2. byte b = 257;

  3. int i = 10;

  4. boolean b = null;

  5. char c = "a";

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

Only 'int i = 10' compiles without error. 'float f = 1.3' fails because 1.3 is a double literal requiring casting or 'f' suffix. 'byte b = 257' fails because 257 exceeds byte's range (-128 to 127). 'boolean b = null' fails because booleans can't be null. 'char c = "a"' fails because "a" is a String, not a char.

Multiple choice general knowledge science & technology
  1. int

  2. array

  3. String

  4. float

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

In Java, primitive data types are the basic built-in types that are not objects. 'int' and 'float' are both primitive types - int is a 32-bit integer and float is a 32-bit floating-point number. Array (B) is not a primitive type - it's a reference type/object. String (C) is also not primitive - it's a class from the java.lang package.

Multiple choice general knowledge
  1. The output is “Equal”

  2. The output in “Not Equal”

  3. An error at " if (x = y)" causes compilation to fall.

  4. The program executes but no output is show on console.

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

In many programming languages like C, Java, and C#, 'if (x = y)' uses the assignment operator (=) instead of comparison (==). This assigns y's value to x, causing a compilation error because the if condition requires a boolean expression. The answer is correctly identified as the compilation error option.

Multiple choice general knowledge
  1. The output is “Equal”

  2. The output in “Not Equal”

  3. An error at " if (x = y)" causes compilation to fall.

  4. The program executes but no output is show on console.

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

In many programming languages like C, Java, and C#, 'if (x = y)' uses the assignment operator (=) instead of comparison (==). This assigns y's value to x, causing a compilation error because the if condition requires a boolean expression. The answer is correctly identified as the compilation error option.

Multiple choice general knowledge
  1. The output is always NO.

  2. The output is always ON.

  3. The output varies and is either NO or ON.

  4. The code does not compile.

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

The code calls worker.run() directly instead of worker.start(). Direct run() calls execute synchronously in the current thread, printing 'N' first, then 'O', resulting in 'NO'. No actual thread spawning occurs, so output is always deterministic.

Multiple choice general knowledge science & technology
  1. int i; /*above main() */

  2. extern int i; /*inside main() */

  3. Both 1 & 2

  4. option 3 if i is defined elsewhere.

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

The code uses variable 'i' without declaring it. Options 1 and 2 alone are insufficient. Option 3 (declaring i as extern inside main) requires i to be defined elsewhere globally - that's what D specifies, making it correct.

Multiple choice general knowledge science & technology
  1. output i=0 j=20

  2. output j=20

  3. compiler error starting from "printf("i = %d",op.i);"

  4. compiler error starting at the end of struct io

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

C structs cannot have member initialization at declaration (int i=0 is invalid). This causes a compiler error at struct definition time, not at the printf statements.

Multiple choice general knowledge
  1. Value of float variable f is :12.3

  2. Value of float variable f is :12

  3. error found on the line "float f =12.3;"

  4. none of the above

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

In Java, floating-point literals like 12.3 are treated as double by default (64-bit). To assign them to a float variable (32-bit), you must either use the 'f' suffix (12.3f) or cast the value. Without this, the compiler will flag an error due to potential loss of precision from double to float.

Multiple choice general knowledge
  1. Compiler error at line 1

  2. Compiler error at line 3

  3. Compiler error at line 4

  4. NullPointerException

  5. StringIndexOutOfBoundsException

  6. Prints “123null”

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

When append(null) is called on a StringBuffer, it appends the string 'null'. Then insert(0, '123') inserts '123' at position 0. The result becomes '123null'. There's no NullPointerException because StringBuffer.append() handles null by converting it to the string 'null'. Option F correctly identifies this output.

Multiple choice general knowledge
  1. Does not compile

  2. Throws IllegalFormatConversionException

  3. Prints 222.46

  4. Prints 222.45

  5. Prints 2.224578

  6. Prints .2224578

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

The format specifier '%.2f' rounds the double value to 2 decimal places. 222.4578 rounded to 2 decimal places is 222.46 (not 222.45, because the third decimal 7 causes rounding up). The printf method compiles and runs without error, printing the rounded value.