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. Compilation Error - Undeclared Identifier

  2. Compilation Error - Syntax

  3. I dont know

  4. Will Compile but no Output

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

An empty function with just a semicolon is valid in C (as a null statement). While void main() is non-standard (standard C requires int main), many compilers accept it. The code compiles and runs, producing no output because there are no printf statements.

Multiple choice technology programming languages
  1. HelloA

  2. HelloB

  3. HelloABCD

  4. HelloD

  5. HelloC

  6. Compilation Error

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

Multi-character constants like 'ABCD' store multiple bytes in an int. The value is implementation-defined, but most compilers store characters in memory order, so 'ABCD' typically evaluates to the last character 'D' (or the integer representing the bytes). The switch matches case 'D', printing HelloD.

Multiple choice technology programming languages
  1. Compilation Error - Cannot define Function inside Function

  2. 50

  3. Cant say

  4. Some Random Number

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

Nested functions (functions defined inside other functions) are a GCC extension, not standard C. When compiled with GCC, this code works correctly and prints 50. Standard C compilers would reject this, but the question assumes GCC compilation based on the correct answer being 50.

Multiple choice technology programming languages
  1. I have started hating C now!!

  2. Hello

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

  4. Hello World

  5. Segmentation fault

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

The printf("Hello") executes first, printing Hello. The return 5 statement then exits the function immediately - code after return is unreachable. While standard C prohibits return with a value in void functions, GCC allows it as an extension. The output is just Hello.

Multiple choice technology programming languages
  1. Case 1

  2. Case 2

  3. Case 3

  4. Default

  5. Compiler Error

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

In Java, the switch expression must evaluate to a compatible type (such as int, char, String, or enum). Using a long variable (i) in a switch statement is illegal and causes a compiler error.

Multiple choice technology programming languages
  1. This won't print

  2. This prints

  3. There's a runtime exception

  4. scenario is not legal

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

In Java, an if statement condition must evaluate to a boolean value. Passing an integer variable i directly into the condition is illegal and causes a compilation error.

Multiple choice technology
  1. True

  2. False

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

This is the standard classic for loop syntax in Java: for(initialization; condition; iteration) statement. The initialization executes once, the condition is checked before each iteration, and the iteration executes after each loop cycle. Java also supports enhanced for-each loops, but this is the fundamental traditional form.

Multiple choice technology programming languages
  1. x=1 and y=1

  2. x=1 and y=2

  3. x=2 and y=2

  4. x=2 and y=1

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

The post-increment operator x++ first returns the current value of x (which is 1), then increments x to 2. So y receives 1 (the original value), and x becomes 2 after the operation. This is a fundamental concept of post-increment vs pre-increment (++x) operators in Java.

Multiple choice technology programming languages
  1. x=1 and y=1

  2. x=2 and y=2

  3. x=1 and y=2

  4. x=2 and y=1

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

This is identical to question 130241. The post-increment operator x++ first returns the current value (1) to y, then increments x to 2. Result: x=2, y=1. The post-increment operator's behavior is that it returns the original value before performing the increment.

Multiple choice technology programming languages
  1. 10

  2. 0

  3. Garbage Value

  4. Compile time error

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

This code causes a compile-time error because local variable x is not initialized before being used. Even though x is assigned inside the if block, the compiler cannot guarantee that the if condition (y>0) will be true at runtime. Java requires local variables to be definitely assigned before use. The compiler sees a path where x could remain uninitialized.

Multiple choice technology
  1. Compilation fails due to an error in line 23.

  2. Compilation fails due to an error in line 29.

  3. A ClassCastException occurs in line 29.

  4. A ClassCastException occurs in line 31.

  5. The value of all four objects prints in natural order.

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

When Arrays.sort() is called on an array containing mixed object types (Integer, String, Boolean), it will fail at runtime with ClassCastException because these types are not mutually Comparable. The sort method attempts to compare elements but cannot compare different types. The exception occurs at line 29 when sort() tries to compare incompatible types during the sorting process.