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. float f=1.3;

  2. int i=10;

  3. char c="a";

  4. byte b=257;

  5. boolean b=null;

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

Only option B compiles cleanly. Option A requires 1.3f to avoid loss-of-precision warning. Option C uses double quotes for String instead of single quotes for char. Option D overflows byte range (-128 to 127). Option E is invalid because boolean is a primitive type and cannot be assigned null.

Multiple choice technology programming languages
  1. Error: anar is referenced before it is initialized

  2. null

  3. 0

  4. 5

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

In Java, when you create an int array using 'new int[5]', all elements are automatically initialized to 0 (the default value for int primitives). Therefore, anar[0] prints 0. This is not an error, not null, and not 5 (the array length, not a value).

Multiple choice technology programming languages
  1. The computer will output "0123...99"

  2. The computer will output "0123...100"

  3. The output is undefined

  4. Don't know

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

In C++, local variables like int x are not automatically initialized to zero. Reading from an uninitialized variable leads to undefined behavior, meaning the initial value of x is unpredictable and the output of the loop is completely undefined.

Multiple choice technology programming languages
  1. Outputs 12

  2. Outputs 10

  3. Outputs the address of v

  4. Compile error

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

The function receives a copy of the pointer to v. Inside the function, x is reassigned to a new memory address (new int), so modifying *x only changes the dynamically allocated integer, leaving the original variable v in main unchanged at 10.

Multiple choice technology programming languages
  1. 2

  2. 0

  3. 3

  4. 2.5

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

The key issue here is that (1 / 4) performs integer division, which results in 0, not 0.25. Then 0 * 10 = 0, so f = 0.0. Math.round(0.0) returns 0, which is printed out. This demonstrates the importance of understanding that integer division truncates toward zero in Java, which can lead to unexpected results when mixed with floating-point operations.

Multiple choice technology programming languages
  1. . Compiler error.

  2. Will throw a NoSuchMethod error at runtime.

  3. It will compile and run printing out "10"

  4. It will run with no output.

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

The code has a static block that calls print(10), which should work since print is a static method. However, the issue is that the static block runs before the main method, and the code has no main method at all. When you try to run this class, the JVM looks for a main method and throws a NoSuchMethodError at runtime because main() is missing. The static block will execute (and would print 10 if main existed), but the program fails due to the missing entry point.

Multiple choice technology programming languages
  1. -23

  2. -22.0

  3. 22.0

  4. 24

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

Math.ceil returns the smallest integer greater than or equal to its argument. For negative numbers, ceiling rounds toward zero (less negative), so ceil(-22.22222) = -22.0, not -23 (which would be floor). The method returns a double type, so the output is -22.0.

Multiple choice technology programming languages
  1. false false false dar

  2. false true false Poddar

  3. Compiler Error

  4. true true FALSE dar

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

The code tests reference and value equality. sb1 == sb2 is false (different objects). StringBuffer doesn't override equals(), so sb1.equals(sb2) is false (uses Object.equals()). sb1.equals(ss1) is false (StringBuffer vs String - different types). 'Poddar'.substring(3) returns 'dar' (0-indexed, starts from 'd'). Output: false false false dar