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

Multiple choice
    • 3 : 4 - 4 : 3
    • 4 : 4 - 3 : 3
    • 4 : 4 - 3 : 3
    • 4 : 3 - 3 : 4
    • 3 : 3 - 4 : 4
Reveal answer Fill a bubble to check yourself
A Correct answer
Explanation

ceil(-3.5) rounds UP to -3 (less negative), ceil(3.5) rounds up to 4. floor(-3.5) rounds DOWN to -4 (more negative), floor(3.5) rounds down to 3. The printf statements output: -3 : 4 (from ceils) then -4 : 3 (from floors).

Multiple choice
  1. 4

  2. 5

  3. 6

  4. 7

  5. 8

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

x starts at 5. Since op='*' doesn't match any case, switch goes to default: x becomes 6. Without break, execution falls through to case '+': x += 2 makes x=8, then case '-': x -= 2 makes x=6. Fallthrough continues through all cases after the matching one.

Multiple choice
  1. It will not compile because not enough initializers are given.

  2. 6

  3. 7

  4. 12

  5. 24

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

testarray[4][3] has 12 elements total (4 rows × 3 columns). Each short is 2 bytes, so sizeof returns 12 × 2 = 24 bytes. The initializer fills only some elements, but sizeof still counts the full array declaration.

Multiple choice
  1. %e always displays an argument of type double in engineering notation; %f always displays an argument of type double in decimal notation.

  2. %e expects a corresponding argument of type double; %f expects a corresponding argument of type float.

  3. %e displays a double in engineering notation if the number is very small or very large. Otherwise, it behaves like %f and displays the number in decimal notation.

  4. %e displays an argument of type double with trailing zeros; %f never displays trailing zeros.

  5. %e and %f both expect a corresponding argument of type double and format it identically. %e is left over from K&R C; Standard C prefers %f for new code.

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

%e displays floating-point in exponential notation (1.234e+05). %f displays in fixed-point decimal notation (123400.000000). Both take double arguments. Option A correctly describes this distinction. Option C is wrong - %e always uses exponential form, not conditionally.

Multiple choice
  1. It will not compile.

  2. It will print out: i=9.

  3. It will print out: i=10.

  4. It will print out: i=11.

  5. It will loop indefinitely

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

The global variable 'i' is used in the for-loop condition and print statement. However, the increment function takes 'int i' as a parameter, which shadows the global variable. The function increments its local parameter, not the global 'i'. Therefore, the global 'i' remains 0 forever, and the loop condition i < 10 is always true, causing an infinite loop.

Multiple choice
  1. 2

  2. 4

  3. 0

  4. 8

  5. Error at line 1

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

This is the correct answer. The operator ( >>) is a right shift operator. The general formula to solve (N >> s) is: N/2^s. Here, 128>>4 will be solved first which is 128/(2^4) = 8. So, the statement now becomes 8>>3>>2. Now 8/(2^3) will be solved which will return (8/8) = 1. Now again the statement becomes 1>>2. So, 1/(2^2) will be solved resulting in 0. The correct output is zero.

Multiple choice
  1. 65536

  2. 1024

  3. 0

  4. 512

  5. Error at line 1

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

Two kinds of operators are used in the statement: left shift (<<) and right shift (>>). The general formula to solve (N << s)  is: N * 2^s, and the general formula to solve (N >> s) is: N/2^s. So, firstly 128<<4<<3<<2 will be solved which will return 128 * (2^4) * (2^3) * (2^2) = 65536. Now the statement becomes 65536 >> 6. So, it will return 65536/2^6 = 1024. The output will be 1024. So, this is the correct answer.

Multiple choice
    • 25
    • 43
    • 9
    • 6
  1. Compiler error

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

This is the correct answer. The compiler will first reverse the bits of  x and y as we have used ~ (tilde) operator on them. So, the expression becomes: -24 | -43. Now, the compiler will convert -25 and -43 into binary and perform OR operation on them. So, the answer will be -9.

Multiple choice
  1. 60

  2. 59

  3. 58

  4. 57

  5. 56

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

This is the correct answer. The operators used here are all bitwise operators which operate on binary bits. So, the value of x in binary is 00011000, the value of  Y in binary is 00101010 and the value of Z in binary is 00100101. The value of variable "a" in binary is 00010110. The expression becomes [ 000011000 & 00101010 | 00100101 ^ 00010110 ]. So, we will evaluate 24 and 42 | 37 ^ 22, which results in 59.

Multiple choice
  1. 64

  2. 59

  3. 62

  4. 63

  5. 77

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

The compiler will first convert all of the given values in binary form. So, value of x in binary is 00011000, value of Y in binary is 00101010, value of Z in binary is 00100101 and value of "a" in binary is 00010110. Now, OR operation will be performed on all of them to obtain a single result: (00011000) | (00101010) | (00100101) | (00010110). It will result in 63. So, this is the correct answer.