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. Prints: false,false,false

  2. Prints: false,true,false

  3. Prints: true,false,false

  4. Prints: true,true,false

  5. Prints: true,true,true

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

In Java, the expression v != v evaluates to true if and only if v is Double.NaN (since NaN is not equal to itself). Thus, v != v is logically equivalent to Double.isNaN(v). Comparing them with == always yields true for any double value, printing 'true,true,true'.

Multiple choice technology programming languages
  1. doStuff x = 6 main x = 6

  2. doStuff x = 5 main x = 6

  3. doStuff x = 5 main x = 5

  4. Compilation fails

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

Java passes primitives by value. The main method passes x=5 to doStuff, which receives a copy. Inside doStuff, x++ increments the copy AFTER printing its current value (5). The original x in main remains unchanged. Output: 'doStuff x = 5' then 'main x = 5'. Option C is correct. If x were an object reference, behavior would differ.

Multiple choice technology programming languages
  1. null

  2. zero

  3. some

  4. Compilation fails

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

The code has a syntax error: 'else (str.length() == 0)' is invalid. The 'else' keyword cannot be followed by a condition in parentheses - that's 'else if'. This causes compilation failure. Option D is correct. If the syntax were corrected to 'else if', str='null' is not null and has length 4, so 'some' would print.

Multiple choice technology programming languages
  1. 2

  2. 2 3

  3. 1 2 3

  4. Compilation fails

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

The first if-condition (x == 4) && !b2 evaluates to false because x is 5, so '1' is not printed. Next, '2' is printed unconditionally. The second if-condition (b2 = true) && b1 assigns true to b2, making the expression true && true, which evaluates to true, so '3' is printed.

Multiple choice technology web technology
  1. The value of the 'test' variable will be 2.

  2. The value of the 'test' variable will be 0.

  3. The value of the 'test' variable will be 1.

  4. The variable 'test' must be declared at global scope, else a run-time error will occur

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

In JSP scriptlets, variables declared without explicit scope are local to the request. Each HTTP request reinitializes test to 0, then increments to 1. The third access still shows 1, not 3.

Multiple choice technology web technology
  1. The value of the 'test' variable will be 2.

  2. The value of the 'test' variable will be 0.

  3. The value of the 'test' variable will be 1.

  4. The variable 'test' must be declared at global scope, else a run-time error will occur

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

The JSP scriptlet <% int test = 0; %> declares a local variable inside the service method. Every time the page is requested, the variable is re-initialized to 0 and incremented to 1, so it always prints 1.

Multiple choice technology web technology
  1. 132

  2. Exception arises

  3. 4

  4. 13

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

In Java, when the + operator is used with a String and any other type, Java performs string concatenation. The integer 3 is converted to its string representation "3" and concatenated with "1", resulting in "13". This is a fundamental Java behavior - the + operator is overloaded for both arithmetic addition and string concatenation. Option A is incorrect (would require different order), Option B is wrong (no exception), Option C would only result from arithmetic addition of integers.

Multiple choice technology programming languages
  1. It will print -10

  2. It will result in Assertion Error showing the message -"The value must not be negative".

  3. The code will not compile.

  4. None of these.

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

The Java assertion statement syntax requires the second expression (after the colon) to return a value. Because methodB() has a void return type, it cannot be used as the detail message expression, causing a compilation error.

Multiple choice technology programming languages
  1. Prints : "I am false interface" followed by " I am false String"

  2. Prints : "I am true interface" followed by " I am true String"

  3. Prints : "I am true interface" followed by " I am false String"

  4. Compile-time error

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

The instanceof operator checks if an object is an instance of a specific type or interface. MyInstanceTest implements MyInterface, so 't instanceof MyInterface' returns true (prints 'I am true interface'). The static variable 's' is null (default value), and 'null instanceof String' returns false (prints 'I am false String'). The instanceof operator safely handles null values by returning false instead of throwing an exception.

Multiple choice technology programming languages
  1. prints: Value is - 9

  2. prints: Value is - 5

  3. Compilation error

  4. None of these

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

The ternary operator expression ((a < 5) ? 9.9 : 9) involves type promotion. Since the second operand (9.9) is a double, the third operand (9) is promoted to double, and the result is 9.0 (not 9). The output is 'Value is - 9.0', which doesn't match option A (9), B (5), or C (compilation error). Therefore D (None of these) is correct. This tests understanding of numeric promotion in ternary expressions.