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. D. 2 3

  2. A. 2 B. 3

  3. C. 1 2 E. 1 2 3

  4. F. Compilation fails. G. Au exceptional is thrown at runtime.

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

Tracing the code: x=5, so x==4 is false, and the first if short-circuits without printing 1. Then 2 is printed. b2 = true assigns true, and b1 is true, so the second if condition is true, printing 3. Output is 2 3. Option A (D. 2 3) matches this.

Multiple choice technology programming languages
  1. D. 2 3

  2. A. 2 B. 3

  3. C. 1 2 E. 1 2 3

  4. F. Compilation fails. G. Au exceptional is thrown at runtime.

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

The first if condition (x==4) && !b2 evaluates to false, so 1 is not printed. Then 2 is printed unconditionally. The second if condition (b2 = true) && b1 assigns true to b2 and evaluates to true, printing 3. The output is 2 3.

Multiple choice technology programming languages
    1. The answer is 0
    1. The answer is 1
    1. The answer is 2
    1. The answer is 3
    1. The answer is 4
Reveal answer Fill a bubble to check yourself
B Correct answer
Explanation

In this code, z == x is false (different object instances), y == x is true (same reference), y == z is false. The equals() calls are misleading - Object's default equals() checks reference equality, so y.equals(z) is false, x.equals(z) is false, z.equals(y) is false. Thus, only TheAnswer = 1 executes, printing 'The answer is 1'.

Multiple choice technology programming languages
  1. for( Color c : Color.values())

  2. for( Color c = RED; c <= BLUE; c++)

  3. for( Color c; c.hasNext() ; c.next())

  4. for( Color c = Color[0]; c <= Color[2]; c++)

  5. for( Color c = Color.RED; c <= Color.BLUE; c++)

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

To iterate over enum constants RED, GREEN, BLUE, use the enhanced for-loop with Color.values() which returns all enum constants. Option A is correct. Options B, C, D, E use incorrect syntax - enums are not array-indexable, don't support hasNext()/next() without iterator, and don't support <= comparison.

Multiple choice technology programming languages
    1. Its: 1
    1. Its: 0
    1. Its: true
  1. 4 Its: false

    1. Its: 0.0
Reveal answer Fill a bubble to check yourself
E Correct answer
Explanation

The variable dSyntaxs is a static member variable of type double. In Java, instance and static member variables of numeric types are automatically initialized to their default values, which is 0.0 for double.

Multiple choice technology programming languages
    1. From an int to a long
    1. From a byte to an int
    1. From a short to a byte
    1. From an int to a double
  1. 5) All of the above

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

Widening conversions (int to long, byte to int, int to double) never lose information because the target type has equal or greater range. A short to byte conversion can lose information if the short value exceeds byte's range (-128 to 127). Since option C may lose data, 'all of the above' is correct.

Multiple choice technology programming languages
    1. byte z;
    1. int z;
    1. char z
    1. None of these options are correct
Reveal answer Fill a bubble to check yourself
B Correct answer
Explanation

Arithmetic on byte, short, and char operands promotes to int. The expression x + y produces an int, which cannot be assigned to byte without an explicit cast. Therefore z must be declared as int to compile.