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

  2. Exception happened / by zero

  3. Exception happened / by zero In finally

  4. In finally

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

The code divides 10 by 0, throwing ArithmeticException '/ by zero'. This is caught by the Exception handler, which prints the message and calls System.exit(0). System.exit() terminates the JVM immediately, so the finally block never executes. Output is only the exception message.

Multiple choice technology programming languages
  1. Exception happened / by zero In finally

  2. Exception happened / by zero

  3. In finally

  4. Compiler Error

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

Division by zero throws ArithmeticException with message '/ by zero'. The catch block prints 'Exception happened / by zero'. Control then proceeds to the finally block, which prints 'In finally'. Both statements execute in sequence.

Multiple choice technology programming languages
  1. Executing...

  2. Please Execute Me Executing... Executed

  3. Error at line 6

  4. Error Semicolon missing

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

The code has empty statements (multiple semicolons) and string literals without statements. String literals not followed by anything are valid expressions that do nothing. Line 6 and 8 are valid no-op expressions. Line 7 printf executes, printing 'Executing...'. No errors occur.

Multiple choice technology programming languages
  1. 1 1.000000

  2. 1 1.500000

  3. 0 1.000000

  4. 1 0.000000

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

Both 6/4 expressions use integer division. In C, int/int truncates toward zero. 6/4 = 1 (integer). The printf uses %d for first (prints 1) and %f for second. %f expects a float/double but receives int 1, causing undefined behavior. The expected output shows 1 and 0.000000 for this UB.

Multiple choice technology programming languages
  1. Let me work

  2. Let me workThis is case 1This is case 2

  3. Compilation Error

  4. Run Time Error

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

In C, the switch statement requires an expression of integer type (int, char, enum). A float variable cannot be used as the switch expression because float values are not discrete and cannot be compared exactly for equality matching. This code will fail to compile with an error about illegal switch expression type. Options A and B would be outputs if the code compiled, but compilation never succeeds.

Multiple choice technology programming languages
  1. The man behind C

  2. Experience the legacy of C

  3. Error : == operator cannot be applied to reference data types

  4. boolean cannot be converted to int

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

In C, comparing two arrays using the == operator compares their memory addresses, not their contents. Even though s1 and s2 contain the same string "Dennis", they are separate arrays stored at different memory locations. Therefore s1 == s2 evaluates to false, and the else branch executes, printing "Experience the legacy of C".

Multiple choice technology programming languages
  1. 0

  2. 1

  3. Infinite loop

  4. -1

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

The for loop has an empty body and uses i-- as its condition. The condition is checked before each iteration. Starting with i=0, the condition i-- evaluates to 0 (false) but decrements i to -1 as a side effect. Since the condition is false, the loop body never executes, and the loop terminates. The printf then outputs -1.

Multiple choice technology programming languages
  1. 777777.........

  2. Compilation Error

  3. 7

  4. None of the above

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

In C, it is legal to declare a local variable with the name main inside the main function. This local variable shadows the outer function name. Thus, printf prints the integer value 7. It compile successfully and does not cause infinite recursion or compiler errors.

Multiple choice technology programming languages
  1. 6

  2. Errror

  3. 1

  4. No output

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

The factorial function has incorrect ternary operator syntax. The code (n == 0)? return 1 : return n* factorial(n-1) is invalid because return statements cannot appear inside a ternary expression in this manner. The correct syntax would be 'return (n == 0) ? 1 : n * factorial(n-1);'. This syntax error causes compilation failure.

Multiple choice technology programming languages
  1. I am in 2

  2. Default I am in 2

  3. Default

  4. Compiler Error

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

The output is I am in 2. The switch expression evaluates x (which is 2). The compiler matches this value directly with case 2, executing its block and printing I am in 2. The default block is only executed if no matching case is found, regardless of its position in the switch.

Multiple choice technology programming languages
  1. in m Default

  2. Compiler Error

  3. in m

  4. default

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

Compilation fails because the case label expression m is not a constant expression. In Java, switch case labels must be constant expressions (like literals or variables declared as static final). Because m is a standard local variable, it cannot be used as a case label.

Multiple choice technology programming languages
  1. in 10 Default

  2. Compiler error

  3. in 10

  4. Exception

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

The switch statement in Java does not support the long type as the expression variable. Switch expressions can only be int, short, char, byte (and their wrapper classes), String (Java 7+), or enum types. Since p is a long, this code will not compile regardless of the case labels used.

Multiple choice technology programming languages
  1. Default I am in 3 I am in 1

  2. Default

  3. No output

  4. Exception

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

The switch expression x has value 2, which does not match either case 3 or case 1. Java executes the default case when there is no match. Since there is no break statement after the default case, execution falls through to case 3 and then to case 1, printing all three outputs.