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. class stars

  2. class moon

  3. class sun

  4. none of the above

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

This code has a compilation error due to diamond inheritance ambiguity. Class stars inherits from both sun and moon, each having a result() method. Calling s.result() is ambiguous - the compiler cannot determine which result() to use. This requires scope resolution (s.sun::result() or s.moon::result()) or virtual inheritance.

Multiple choice
  1. class stars

  2. class moon

  3. class sun

  4. none of the above

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

This code has a compilation error due to diamond inheritance ambiguity. Class stars inherits from both sun and moon, each having a result() method. Calling s.result() is ambiguous - the compiler cannot determine which result() to use. This requires scope resolution (s.sun::result() or s.moon::result()) or virtual inheritance.

Multiple choice
  1. True

  2. False

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

The Color constructor Color(int r, int g, int b) requires RGB values to be in the range 0-255. The value 260 in the green component exceeds this maximum valid range, making this statement incorrect. Valid RGB values must be between 0 and 255 inclusive.

Multiple choice
  1. 1 2 3 4 5 6 7 8 9

  2. 1 2 3 10

  3. 4 5 6 7 8 9 10

  4. 4 5 6 7 8 9

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

The while loop increments s using post-increment (s++). Initially s=0, after check s becomes 1. The condition (s<4 && s<9) is true for s=1,2,3, so continue skips printf. When s=4, the condition fails and printing starts. Output continues through s=10 when the loop condition (10<10) becomes false. Output: 4 5 6 7 8 9 10

Multiple choice
  1. 387

  2. 738

  3. 800

  4. 700

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

The function prints digits in reverse order. It repeatedly extracts the last digit using n % 10 (7, then 3, then 8 for 837) and divides n by 10. The do-while ensures at least one iteration. So f(837) prints '738' followed by newline. Option A is in reverse order, C and D are incorrect values.

Multiple choice
  1. 1.66, 1 (That is, '1.66', a comma, a space, a '1', and a newline character)

  2. 1.6, 2 (That is, '1.6', a comma, a space, a '2', and a newline character)

  3. 1.666, 0 (That is, '1.666', a comma, a space, a '0', and a newline character)

  4. 1, 2 (That is, a '1', a comma, a space, a '2', and a newline character)

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

In C, integer division (5/3) truncates toward zero, yielding 1 (not 1.66 or decimal values). The modulo operator (5 % 3) gives the remainder, which is 2. Therefore printf with '%d, %d' format prints '1, 2'. The fractional answers A, B, C are incorrect because %d expects integers.

Multiple choice
  1. x = 0

  2. x = 1

  3. x = 4

  4. x = 5

  5. x = 6

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

The loop uses post-increment (x++), which means the current value is compared first, then x is incremented. When x=4, the condition (x++4) is true (44), then x becomes 5, and the break executes. The printf shows x=5, not x=4, because the increment happens after the comparison.

Multiple choice
  1. z = 0.00

  2. z = 1.00

  3. z = 1.50

  4. z = 2.00

  5. z = NULL

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

When dividing two integers (6/4), C performs integer division, not floating-point division. The result is 1 (the decimal part is truncated), which is then stored in double variable z and printed as 1.00. To get 1.50, you would need to cast one operand to double first.

Multiple choice
  1. 6

  2. 7

  3. 8

  4. 9

  5. The code will not compile

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

ptr is assigned y+2, which points to the third element (index 2, value 8). ptr[1] means *(ptr+1), which accesses the next element (index 3, value 9). Array indexing with pointers works by adding the index to the base pointer and dereferencing.

Multiple choice
  1. fg

  2. efg

  3. defg

  4. cdefg

  5. None of the above

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

ptr starts at index 0 pointing to 'a'. After ptr += 5, it points to index 5, which is 'f'. The string from that position is 'fg' (characters at indices 5 and 6). This is basic pointer arithmetic where the pointer moves forward by the specified number of elements.