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

  2. 10

  3. 11

  4. false

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

The answer is 10 because Java uses short-circuit evaluation for the && operator. Since y > 10 is false (y equals 10), the second condition (x++ > 10) is never evaluated, so the increment x++ doesn't execute. This means x remains 10. Option C (11) would only occur if the increment executed, and options A and D are nonsensical in this context.

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

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.