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. 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. The program terminates

  2. You get an overflow error

  3. The value becomes a negative value

  4. The value becomes zero

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

When a signed integer overflows (value exceeds maximum representable), it wraps around due to two's complement representation. The most significant bit (sign bit) flips, making the value negative. For example, if INT_MAX is 2147483647, adding 1 gives -2147483648 (INT_MIN). This is undefined behavior in C/C++ but typically results in wraparound.

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. Standard C defines this particular behavior as implementation-dependent. The compiler writer has the freedom to decide how the remaining elements will be handled.

  2. The remaining elements are initialized to zero(0).

  3. It is illegal to initialize only a portion of the array. Either the entire array must be initialized, or no part of it may be initialized.

  4. As with an enum, the compiler assigns values to the remaining elements by counting up from the last explicitly initialized element. The final four elements will acquire the values 4, 5, 6, and 7, respectively.

  5. They are left in an uninitialized state; their values cannot be relied upon.

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

In C, when an array is partially initialized, all remaining elements are automatically initialized to zero. The compiler fills the uninitialized elements (a[4] through a[7]) with zeros. This is guaranteed by the C standard and not implementation-dependent.

Multiple choice
  1. fscanf() will fail to match floating-point numbers not preceded by whitespace.

  2. The format specifier %lf indicates that the corresponding argument should be long double rather than double.

  3. The call to fscanf() requires a pointer as its last argument.

  4. The format specifier %lf is recognized by fprintf() but not by fscanf().

  5. D must be initialized prior to usage.

Reveal answer Fill a bubble to check yourself
B Correct answer