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 technology programming languages
  1. 1 2 3

  2. Compile error , can't add primitive type in ArrayList

  3. Compile error on for(int i:list) , Incorrect Syntax

  4. 0 0 0

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

Java autoboxing automatically converts primitive int values to Integer objects when adding to ArrayList. The enhanced for loop iterates through each element and prints it on a separate line. Options B and C are incorrect because autoboxing and the for-each syntax are both valid in Java.

Multiple choice technology programming languages
  1. Prints out: Exception Finally

  2. Prints out: Finally

  3. Prints out: Exception

  4. Compile with error

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

When dividing 0 by 3, the result is 0 (no exception occurs because the denominator is non-zero). The try block completes successfully, so the catch block is skipped. The finally block always executes regardless of whether an exception occurred, printing 'Finally'.

Multiple choice technology programming languages
  1. 0

  2. Compile with error

  3. null

  4. NullPointerException

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

Attempting to unbox a null Integer reference to a primitive int throws a NullPointerException. This happens at runtime during the assignment 'int j = i' because Java cannot convert null to a primitive value. Option A is incorrect (null doesn't become 0), and B is wrong because this compiles fine but crashes at runtime.

Multiple choice technology architecture
  1. Number of bytes transferred per hour

  2. Number of reports generated per day

  3. Number of errors per hour

  4. Number of requests handled by the application per day

  5. Number of hits per second

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

Throughput measures work done per unit time (transactions/day, bytes/second, requests/minute). Options A, B, D, and E all measure completed work. Errors per hour measures failure rate, not throughput - it's a quality/reliability metric, not a productivity metric.

Multiple choice technology programming languages
  1. NullPointerException

  2. It works properly

  3. Compile Error : No readPassword() method in Console class

  4. null

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

The code has an infinite loop: auth is never set to true, so the condition (!auth && ++count < 3) will keep running until count reaches 3. The readLine() call with null argument will throw NullPointerException. The code demonstrates incorrect Console API usage and a logic bug. Option A is correct - NullPointerException occurs.

Multiple choice technology programming languages
  1. compile time error at line 1

  2. compile time error at line 2

  3. compile time error at line 3

  4. prints 9

  5. Runtime exception

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

In Java, an interface can define a nested class, which is implicitly public and static. A final nested class is legal, and defining a static member inside it is also valid. The code compiles without issues and successfully prints 9.

Multiple choice technology programming languages
  1. Prints: false,false

  2. Prints: true,false

  3. Prints: false,true

  4. Prints: true,true

  5. None of the above

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

StringBuffer's equals() method compares object references (inherited from Object), not content. So sb2.equals(s1) returns false because they're different objects. String's equals() compares content, but it only returns true when comparing with another String, so s1.equals(sb2) returns false. Output is false,false. Option A is correct.

Multiple choice technology programming languages
  1. x = 4, y = 1, z = 5

  2. x = 3, y = 2, z = 6

  3. x = -7, y = 1, z = 5

  4. x = 4, y = 2, z = 6

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

To solve this question, the user needs to know the order of operations in C programming and the difference between pre-increment and post-increment operators.

First, let's break down the expression x = 0 - (++y) + z++:

  1. ++y is a pre-increment operator, which means it increments the value of y by 1 before the value is used in the expression. So, y becomes 2.
  2. z++ is a post-increment operator, which means it increments the value of z by 1 after the value is used in the expression. So, z remains 5 in this expression.
  3. The expression inside the parentheses is evaluated first, so ++y is evaluated to 2.
  4. Next, the multiplication and division are evaluated from left to right, but there are none in this expression.
  5. Finally, the addition and subtraction are evaluated from left to right.

So, 0 - (++y) evaluates to -2 and z++ evaluates to 5, therefore the whole expression evaluates to -2 + 5 = 3.

Therefore, the correct answer is:

The Answer is: B. x = 3, y = 2, z = 6

Multiple choice technology programming languages
  1. (A), (B), (D) & (E)

  2. (B), (C) & (D)

  3. (B), (D), (E) & (F)

  4. (B), (D) & (E)

  5. (D) & (F)

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

In Java, arithmetic operations on byte values are promoted to int. The expression b1 * b2 (5 * 10 = 50) produces an int result. This int can be assigned to int, long, float, or double through widening conversions. It cannot be assigned directly to byte or short without explicit casting.

Multiple choice technology programming languages
  1. error

  2. 5

  3. garbage number

  4. 3

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

In Python, negative indexing access elements from the end of the list. The index -1 retrieves the last element, which is 5. It does not produce an error or return a garbage value.

Multiple choice technology programming languages
  1. Bic

  2. ic

  3. icy

  4. error: no method matching substring(int,char)

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

The substring method in Java extracts characters from index begin (inclusive) to end (exclusive). With s='Bicycle', begin=1, end=3, it extracts characters at positions 1 and 2, which are 'i' and 'c', resulting in 'ic'. Note that iEnd is char but gets promoted to int.

Multiple choice technology programming languages
  1. A circle at (100, 100) with radius of 44

  2. A circle at (100, 44) with radius of 100

  3. A circle at (100, 44) with radius of 44

  4. The code does not compile

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

The code contains a compilation error - the paint() method signature is incorrect as it's missing proper parameters or doesn't override a valid method. Without seeing the actual method signature and body, the code cannot compile successfully.

Multiple choice technology programming languages
  1. 0

  2. 1

  3. 2

  4. 3

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

Due to short-circuit evaluation, the first expression (t && ((i++) == 0)) executes i++ making i=1. The second expression (f && ((i+=2) > 0)) short-circuits because f is false, so i+=2 never executes. Final i=1.

Multiple choice technology web technology
  1. true

  2. false

  3. Compile Error

  4. None of the above

Reveal answer Fill a bubble to check yourself
B Correct answer