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
  1. 288 0

  2. 32 1

  3. 0 1

  4. Compilation error

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

In C int, datatype is of 2 bytes while char pointer pt will take only one byte. Binary representation of 32 is 00000000 00100000.  The pr pointer will first point the second byte, and then the first byte. So, second byte will be represented by 00100000, i.e. 32 and first byte will be represented by 00000000, i.e. 0. Hence, the output will be 32 0.

Multiple choice
  1. void main() { int i; for(i=65;i<=71;printf(%d,i),i++); }

  2. void main() { int i; for(i=65;i<=71;printf(%c,i)); }

  3. void main() { int i; for(i=65;i<=71;printf(%c,i),i++); }

  4. void main() { int i; for(i=65;i<=70;printf(%c,i),i++); }

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

Loop will execute for i = 65 to 71. The ASCII value of 'A' = 65 and ASCII value of 'G' = 71 Hence, the output will be “ABCDEFG”.

Multiple choice
  1. 9.0

  2. bad number

  3. Compilation fails on line 13.

  4. Compilation fails on line 14.

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

The xxxValue() methods convert any numeric wrapper object's value to any primitive type. When narrowing is necessary, significant bits are dropped and the results are difficult to calculate.

Multiple choice
  1. 12 15

  2. 15 15

  3. 3 4 5 3 7 5

  4. 3 7 5 3 7 5

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

The reference variables a1 and a3 refer to the same long array object. When the [1]element is updated in the fix() method, it is updating the array referred to by a1. The reference variable a2 refers to the same array object. So Output: 3+7+5+" "3+7+5 Output: 15 15 Because Numeric values will be added

Multiple choice
  1. 0

  2. 7

  3. 8

  4. 14

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

The & operator produces a 1 bit when both bits are 1. The result of the & operation is 9. The ^ operator produces a 1 bit when exactly one bit is 1; the result of this operation is 10. The | operator produces a 1 bit when at least one bit is 1; the result of this operation is 14.

Multiple choice
  1. ok

  2. dokey

  3. ok dokey

  4. No output is produced

  5. Compilation error

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

The & operator has a higher precedence than the | operator so that on line 8 b1 and b2are evaluated together as are b2 & b3. The final b1 in line 10 is what causes that if test to be true. Hence it prints "dokey".

Multiple choice
  1. f[0] = 0

  2. f[0] = 0.0

  3. Compile Error

  4. Runtime Exception

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

The choices are between Option A and B, what this question is really testing is your knowledge of default values of an initialized array. This is an array type float i.e. it is a type that uses decimal point numbers therefore its initial value will be 0.0 and not 0

Multiple choice
  1. This code will not compile due to line 5.

  2. This code will not compile due to line 6.

  3. 1..2..

  4. 1..2..3..

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

Line 6 calls the run() method, so the run() method executes as a normal method should and it prints 1..2.. Option 1 is incorrect because line 5 is the proper way to create an object. Option 2 is incorrect because it is legal to call the run() method, even though this will not start a true thread of execution. The code after line 6 will not execute until the run() method is complete. Option 4 is incorrect because the for loop only does two iterations.

Multiple choice
  1. An exception occurs at runtime at line 10.

  2. It prints "Zippo".

  3. Compilation fails because of an error on line 7.

  4. Compilation fails because of an error on line 13.

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

The code in the HorseTest class is perfectly legal. Line 13 creates an instance of the method-local inner class Horse, using a reference variable declared as type Object. Line 14 casts the Horse object to a Horse reference variable, which allows line 15 to compile. If line 14 were removed, the HorseTest code would not compile, because class Objectdoes not have a name variable.

Multiple choice
  1. An error at line 11 causes compilation to fail

  2. Errors at lines 8 and 9 cause compilation to fail.

  3. The program prints pairs of values for x and y that might not always be the same on the same line (for example, "x=2, y=1")

  4. The program prints pairs of values for x and y that are always the same on the same line (for example, "x=1, y=1". In addition, each value appears once (for example, "x=1, y=1" followed by "x=2, y=2")

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

The synchronized code is the key to answering this question. Because x and y are both incremented inside the synchronized method they are always incremented together. Also keep in mind that the two threads share the same reference to the Q126 object. Also note that because of the infinite loop at line 13, only one thread ever gets to execute.

Multiple choice
  1. 18

  2. 117

  3. 567

  4. Compiler error

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

This question is about the + (plus) operator and the overriden + (string cocatanation) operator. The rules that apply when you have a mixed expression of numbers and strings are: If either operand is a String, the + operator concatenates the operands. If both operands are numeric, the + operator adds the operands. The expression on line 6 above can be read as "Add the values i1 and i2 together, then take the sum and convert it to a string and concatenate it with the String from the variable s1". In code, the compiler probably interprets the expression on line 8 above as: System.out.println( new StringBuffer()     .append(new Integer(i1 + i2).toString())     .append(s1)     .toString() );