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
  1. HelloD

  2. HelloC

  3. HelloB

  4. HelloA

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

The variable ch is declared as char but assigned 'ABCD' (a multi-character constant). In C, this implementation-defined behavior results in only the last character 'D' being stored (due to little-endian byte order). The switch matches case 'D' and prints 'HelloD'.

Multiple choice general knowledge
  1. Hello World

  2. Compilation Error - Cannot return when return type is Void

  3. Hello

  4. Segmentation fault

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

In C, a return statement causes the function to exit immediately, even if the return type is void. The 'return 5;' is valid - the 5 is simply discarded. The printf(" World") after return is never reached because execution terminates at return. Output is 'Hello'.

Multiple choice general knowledge
  1. a. Will Compile but no Output

  2. b. Compilation Error - Undeclared Identifier

  3. c. Compilation Error - Syntax

  4. d. I dont know

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

An empty statement (just a semicolon) is valid in C. The function main contains only a semicolon, which does nothing. This compiles successfully and produces no output. Option A is correct.

Multiple choice general knowledge science & technology
  1. compilation error

  2. TCS Hyd

  3. runtime error

  4. non of above

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

The preprocessor concatenates 'TCS' and 'Hyd' into a single string literal 'TCS Hyd'. The ## operator performs token pasting during preprocessing, before compilation. This is valid preprocessor syntax that results in a single string that printf will output correctly. There's no compilation or runtime error - the code works as intended.

Multiple choice general knowledge science & technology
  1. The program has a syntax error

  2. The program has a runtime error

  3. The program runs fine, but displays nothing

  4. The program runs fine and displays It is even!

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

The program prints 'It is even!' because the if condition uses assignment (=) instead of equality comparison (==). The statement 'even = true' assigns true to the variable even and returns true as the expression result, so the if block executes. This is a common mistake - using assignment instead of comparison. There is no syntax or runtime error, and output is produced.

Multiple choice general knowledge science & technology
  1. 5

  2. 6

  3. 7

  4. 8

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

The loop executes three iterations: item=1 adds 1 to sum (sum=1), item=2 adds 2 (sum=3), item=3 adds 3 (sum=6). When sum becomes 6, it exceeds 4 and the break statement exits the loop before checking the while condition.

Multiple choice general knowledge science & technology
  1. A

  2. AB

  3. AC

  4. ABC

  5. compile-time error

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

Strings in Java are immutable - the concat() method returns a new String but does not modify the original. So str.concat("B") is ignored. The += operator creates a new String "AC" and assigns it back to str.

Multiple choice general knowledge science & technology
  1. The program cannot compile because the compiler cannot determine which max method should be invoked

  2. The program cannot compile because you cannot have the print statement in a non-void method

  3. The program runs and prints "max(int, double) is invoked" followed by 2

  4. The program runs and prints "max(double, int) is invoked" followed by 2

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

When max(1, 2) is called with two int arguments, Java's compiler cannot determine whether to invoke max(int, double) or max(double, int) since both require an implicit type conversion (int to double). This ambiguity causes a compilation error.

Multiple choice general knowledge science & technology
  1. The program runs and prints 2 once

  2. The program runs and prints 2 twice

  3. The program has a syntax error because the second m method is defined, but not invoked in the main method

  4. The program has a syntax error because the two methods m have the same signature

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

Methods are distinguished by their signature - the method name AND parameter list (types and order). Both m() methods have the same signature (m(int)) - only the return type differs, which is not sufficient for overloading. This causes a compilation error.

Multiple choice general knowledge science & technology
  1. false false false dar

  2. false true false dar

  3. true true false dar

  4. compile-time error

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

sb1==sb2 returns false (different StringBuffer objects). StringBuffer doesn't override equals(), so sb1.equals(sb2) is false. sb1.equals(ss1) is false (different types). "Poddar".substring(3) returns "dar" (from index 3 to end). Output: false false false dar

Multiple choice general knowledge science & technology
  1. javaFundamentals u

  2. jivi i

  3. java i

  4. jiviFundamentals u

  5. compile-time error

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

Strings are immutable in Java. s1 remains "java" (concat returns new string, not assigned). s2 = "jivi". s1+s2 = "javajivi", charAt(5) = 'i' (0-indexed: j=0, a=1, v=2, a=3, j=4, i=5). Output: "java i"

Multiple choice general knowledge science & technology
  1. Program compiles correctly and prints "A" and "C" when executed

  2. Program compiles correctly and prints "A" when executed

  3. Program compiles correctly and prints "A","B" and "C" when executed

  4. Program compiles correctly and prints "A" and "B" when executed

  5. compile-time error

  6. run-time error

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

When System.exit(0) is called, the JVM terminates immediately without executing the finally block. The program prints A (before try), then B (inside try), then exits. The catch block is not executed because no exception is thrown, and finally is not reached because System.exit() terminates the program.

Multiple choice general knowledge science & technology
  1. compile-time error

  2. run-time error

  3. 0..1..2..

  4. 0..1..2..3..

  5. 1..2..3..

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

The code has a compile-time error. The main method is missing its closing brace - line 8 starts the try block but the main method never closes before the run method is declared. This makes the code structurally invalid and it will not compile.

Multiple choice general knowledge science & technology
  1. run-time error

  2. aabbaabb

  3. bbbbaaaa

  4. abababab

  5. aaaabbbb

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

The code creates two PrintChar objects and calls run() directly (not start()). This means they run sequentially in the main thread, not as separate threads. printA.run() completes first (printing 'aaaa'), then printB.run() executes (printing 'bbbb'), resulting in 'aaaabbbb'. The code doesn't actually create multi-threading.