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

  2. 20

  3. 16

  4. 4

  5. Compiler error

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

This is the correct choice. First the value of variable k will be incremented and it will become 128 as we have used pre-increment operator and also the value of variable j will be pre-incremented and will become 4. So, the expression becomes 128>>4>>2. Variable i will be incremented after the evaluation of expression because we have used post-increment operator with it. So, solving this expression, the result comes out to be: 128/(2^4)/(2^2) => 32. Now as we have used %hx in the printf statement, so the value of 32 will be converted to hexadecimal, which is 20. So, 20 is the correct answer.

Multiple choice
  1. ByeHello Keep CalmGet Lost

  2. Hello Keep CalmGet Lost

  3. Keep CalmGet Lost

  4. Get Lost

  5. Compiler error

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

The value of variable [ i ] after evaluating the expression would be (128 * (2^2) * (2^1) * (2^0)) = 1024. So, the switch case would become switch (1024). Now, the case expressions will be solved and the case having value 1024 will be executed. The first case evaluates to 1024. Therefore, all the statements of first case and all the other preceding cases will be executed until a break keyword is found. So, the output will be: Hello Keep CalmGet Lost. So, this answer is true.

Multiple choice
  1. ByeHelloKeep CalmGet Lost

  2. HelloKeep CalmGet Lost

  3. Keep CalmGet Lost

  4. Get Lost

  5. Blank screen

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

The value of variable 'i', after evaluating the expression, would be (128 / (2^3) / (2^2) / (2^2)) = 1. So, the switch case would become switch(1). Now the case expressions will be solved and the case having value 1 will be executed. None of the cases has value 1; so no output will be printed on the screen. So, this answer is true.

Multiple choice
  1. Hello Good ByeSee U Later

  2. Bye

  3. Bye Hello Good Bye See U Later

  4. Good ByeSee U Later

  5. Error at line 1

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

This is the correct answer. The value of variable [ i ], after evaluating the expression (128<<4<<3<<2>>6), will be 1024. The expression will be evaluated as: (128 * (2^4) * (2^3) * (2^2)) / (2^6) = 65536/64 = 1024. But we do not have any case of 1024 in switch statement; so default case will be executed and it will print “Bye”. But after default, we don’t have any break keyword; so all the cases will be executed until the break keyword is found. So, the correct output will be: Bye Hello Good Bye See U Later.

Multiple choice
  1. 5

  2. 6

  3. 10

  4. 11

  5. 12

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

First calculate --y = -11 (pre-decrement), then x++ uses 5 (post-increment, x becomes 6 after). The expression --y * b / a = -11 * 2 / 4 = -22 / 4 = -5 (integer division). So z = 5 - (-5) = 10. Remember operator precedence: postfix ++ has highest precedence, then prefix --, then *, /, then +, -.

Multiple choice
  1. 3

  2. 5

  3. 7

  4. 9

  5. 11

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

The 3D array is stored in row-major order. testarray[3][2][2] means 3 blocks of 2x2 arrays. The elements are stored as: [0][0][0]=1, [0][0][1]=2, [0][1][0]=3, [0][1][1]=4, [1][0][0]=5, [1][0][1]=6, [1][1][0]=7, [1][1][1]=8, [2][0][0]=9, [2][0][1]=10, [2][1][0]=11, [2][1][1]=12. So testarray[2][1][0] = 11.

Multiple choice
  1. 12,10,11,13

  2. 22,10,11,13

  3. 22,11,11,11

  4. 12,11,11,11

  5. 22,13,13,13

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

Starting with a=10: b = a++ + ++a = 10 + 12 = 22. After this, a=13 (a++ made it 11, ++a made it 12, then sequence completes at 13). In printf: b=22 (no change), a++ prints 13 then makes a=14, a prints 14, ++a makes a=15 then prints 15. Output: 22,13,13,13. This demonstrates undefined behavior in C - the order of evaluation of printf arguments is not specified.

Multiple choice
  1. 1, 2, 3, 4, 5, 5

  2. 4, 3, 2, 1, 0, 0

  3. 5, 4, 3, 2, 1, 0

  4. 0, 0, 1, 2, 3, 4

  5. 0, 1, 2, 3, 4, 5

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

myFunc recursively calls itself with decremented x until x=0, then unwinds printing each x value. For x=5, the call stack builds: myFunc(5)->myFunc(4)->myFunc(3)->myFunc(2)->myFunc(1)->myFunc(0). At x=0, recursion stops. Then prints happen during unwinding: 0,0,1,2,3,4 (note: myFunc(0) prints 0 twice - once after base case, and main's myFunc(5) eventually prints 0 after all recursive calls complete).

Multiple choice
    • 3
  1. 0

  2. 4

  3. 4 + sizeof( int )

  4. 4 * sizeof( int)

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

ptr is set to x+4 (address of 5th element, value 1). ptr-x gives the number of elements between the two pointers, not the byte difference. Since ptr is 4 elements ahead of x, ptr-x=4. Pointer arithmetic on array elements gives element count, not byte offset.

Multiple choice
  1. x = 0

  2. x = 1

  3. x = 3

  4. x = 4

  5. x = 5

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

The for loop increments x until x<4 becomes false. The loop runs for x=1, 2, 3, then when x becomes 4, the condition fails. The semicolon after for(x=1; x<4; x++); makes the loop body empty, so only the increment happens. After loop exit, x equals 4, which printf displays.

Multiple choice
  1. 1

  2. 2

  3. 3

  4. 4

  5. 5

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

The loops store ctr values in transposed index order: myArray[j][i] where i is outer (0-2) and j is inner (0-1). After all iterations: myArray[0]=[0,2,4], myArray[1]=[1,3,5]. Therefore myArray[1][2] equals 5. The 2x3 array is filled column-wise due to swapped indices.

Multiple choice
  1. Hello ItalyHello Paris

  2. Hello Paris

  3. Bye Hello ItalyHello Paris

  4. Compiler Error

  5. Run time exception

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

This is the correct answer.

Multiple choice
  1. ByeHello ItalyHello ParisHello London

  2. Hello ItalyHello ParisHello London

  3. Hello ParisHello London

  4. Hello London

  5. Compiler error

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

This is the correct answer.