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
  1. 922

  2. 32767

  3. 923

  4. 999

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

The sum from 0 to 922 is 32287. If 923 is added with 32287, the sum will be 33210, which is outside the range of integer data type. Hence, n up to 922 can give the desired output.

Multiple choice
  1. Compile error

  2. Linker error

  3. No error

  4. Runtime error

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

It runs properly if the message is to be typed as it is in the scanf() statement, and then enter the values of t and c. For example, After running the program: Enter the values of t and c = 45 67 The output will be t = 45 c = 67

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. If assertions are compiled into a source file, and if no flags are included at runtime, assertions will execute by default.

  2. As of Java version 1.4, assertion statements are compiled by default.

  3. With the proper use of runtime arguments, it is possible to instruct the VM to disable assertions for a certain class, and to enable assertions for a certain package, at the same time.

  4. When evaluating command-line arguments, the VM gives -ea flags precedence over -da flags.

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

Option C is true because multiple VM flags can be used on a single invocation of a Java program. Option A is incorrect because at runtime assertions are ignored by default. Option B is incorrect because as of Java 1.4 you must add the argument -source 1.4 to the command line if you want the compiler to compile assertion statements. Option D is incorrect because the VM evaluates all assertion flags left to right.

Multiple choice
  1. int a = Math.abs(-5);

  2. int b = Math.abs(5.0);

  3. int c = Math.abs(5.5F);

  4. int d = Math.abs(5L);

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

The return value of the Math.abs() method is always the same as the type of the parameter passed into that method. In the case of A, an integer is passed in and so the result is also an integer which is fine for assignment to "int a". The values used in B, C & D respectively are a double, a float and a long. The compiler will complain about a possible loss of precision if we try to assign the results to an "int".

Multiple choice
  1. Compilation will succeed.

  2. Compilation will fail at line 3.

  3. Compilation will fail at line 5.

  4. Compilation will fail at line 15.

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

Option B is correct. The compiler complains with the error "modifier private not allowed here". The class is created private and is being used by another class on line 19.

Multiple choice
  1. true

  2. false

  3. Compilation fails

  4. An exception is thrown at runtime

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

The code will not compile because in line 7, the line will work only if we use (x==y) in the line. The == operator compares values to produce a boolean, whereas the = operator assigns a value to variables. Option A, B, and D are incorrect because the code does not get as far as compiling. If we corrected this code, the output would be false.

Multiple choice
  1. 0

  2. 1

  3. 2

  4. Compilation fails.

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

Compilation failed because static was an illegal start of expression - method variables do not have a modifier (they are always considered local).

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