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

  2. aaaammmmnnnn

  3. aaaannnnmmmm

  4. Compilation Error

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

The loop iterates 3 times (for 'm','a','n'). In each iteration, four expressions print the same character: s[i](array indexing), *(s+i) (pointer dereference), *(i+s) (pointer arithmetic with reversed order), and i[s](array indexing with swapped indices). This is valid C syntax. Each character prints 4 times sequentially: mmmm aaa nnnn.

Multiple choice technology programming languages
  1. 1 2 3 4 5

  2. 5 4 3 2 1

  3. compilation error

  4. None

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

The variable 'var' is static, meaning it retains its value between recursive calls of main(). In each call, printf prints 'var' before it is decremented post-evaluation (post-decrement). If 'var' is non-zero after decrement, main() is called again. The sequence printed is 5, 4, 3, 2, 1, stopping when 'var' becomes 0.

Multiple choice technology programming languages
  1. 3 4 6 5 2 2 2 2 2 2

  2. 4 6 5 2 2 2 2 2 2 3

  3. 2 2 2 3 4 6 5 2 2 2

  4. 2 2 2 2 2 2 3 4 6 5

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

The array c is initialized with float values that are truncated to integers: {2, 3, 4, 6, 5}. The first loop prints *c (which is c[0], i.e., 2) five times, outputting ' 2 2 2 2 2 '. The second loop prints the dereferenced pointer p (which starts at c and increments), outputting the individual elements ' 2 3 4 6 5 ' sequentially. Combined, this outputs ' 2 2 2 2 2 2 3 4 6 5 '.

Multiple choice technology programming languages
  1. 1 3 1 0 0

  2. 0 1 0 1 3

  3. 0 0 3 1 1

  4. 0 0 1 3 1

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

The expression evaluates left-to-right with short-circuit: i++&&j++&&k++||l++. First, i++ uses -1 (false), so i becomes 0 and the entire AND chain short-circuits (j++, k++ don't execute). Since -1 is false, the OR evaluates l++, making l=3. m = (-1) || 3 = 1. Final: i=0, j=-1, k=0, l=3, m=1.

Multiple choice technology programming languages
  1. I Know C

  2. I Don't Know C

  3. Compilation error

  4. None

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

When comparing float (1.1) with double (1.1), precision differs. float 1.1 is stored as 1.10000002384185791016, double 1.1 is 1.10000000000000008882. They are NOT equal. Thus the else branch executes, printing 'I Know C'. This demonstrates floating-point precision differences between types.

Multiple choice technology programming languages
  1. Runtime Exception

  2. Compilation error at line 1

  3. 2

  4. Compilation error at line 2

  5. Compilation error at line 3

  6. Compilation error at line 4

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

The code has a compilation error because 'void' is misspelled as 'voi' in the method signature. Additionally, the syntax 'ArrayList;' is incorrect, and List is an abstract interface that cannot be instantiated directly with 'new List()'. The compilation fails at line 1 due to the typo in the method declaration.

Multiple choice technology programming languages
  1. VALUE OF WS-COUNT: 0

  2. VALUE OF WS-COUNT: 1

  3. Compile error

  4. None of the above

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

WS-COUNT starts at ZERO (0). The IF condition is true, so NEXT SENTENCE executes. In COBOL, NEXT SENTENCE skips to the next statement after the next period (sentence terminator). Since END-IF is not a period, and the ADD statement comes after END-IF in the same sentence, NEXT SENTENCE within the IF would skip over both the IF body AND the ADD statement until it finds the next period. Thus WS-COUNT remains 0.

Multiple choice technology programming languages
  1. Compilation error, attempting to perform binary comparison on logical data type.

  2. Compilation and output of "We are equal 10".

  3. Compilation and output of "Not equal! 20".

  4. Compilation and output of "Not equal! 10".

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

The code uses short-circuit AND (&&). Since b1 is false, (b1 == true) evaluates to false, so the right side ((Output += 10) == 20) is never executed due to short-circuiting. Output remains 10, the if condition is false, and the else branch prints "Not equal! 10". Option A is wrong because you can compare booleans with ==. Option C is wrong because Output is never incremented to 20.

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

In Java's ternary operator, if the second and third operands have different numeric types, binary numeric promotion applies. Here, the expression's overall type is promoted to double, converting 9 to 9.0, resulting in Value is - 9.0. None of the specific print distractors matches.

Multiple choice technology programming languages
  1. 0122

  2. 0123

  3. Compilation error

  4. None of these

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

The variable i is declared within the for-loop initialization (int i = 0), so its scope is limited to the loop block. The statement System.out.print(i) outside the loop cannot access i because it's out of scope, causing a compilation error. Option B would be correct if i were declared before the loop.

Multiple choice technology programming languages
  1. Compilation Error

  2. Prints : Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes and so on.

  3. Prints : No No No No No No No No No No and so on.

  4. Prints : Yes No Yes No Yes No Yes No Yes No and so on.

  5. The Output cannot be determined.

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

Because a new thread is spawned to modify the shared variable without synchronization, there is a race condition between the main loop printing the variable and the child thread writing to it. The output depends on JVM thread scheduling and is therefore unpredictable.