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

  2. ByeGoodBad

  3. GoodBad

  4. Bad

  5. Compiler error

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

There is an error in the code because we have put a semicolon after the switch() statement which is invalid. The compiler will raise an error “case label not with a switch statement”. So, this answer is correct.

Multiple choice
  1. 0 GoodBad

  2. 8ByeGoodBad

  3. 14HelloByeGoodBad

  4. 16

  5. Compiler error

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

This is the correct choice because the last two cases: “case 0/9” and “case 0/1” both will evaluate to 0. But we cannot have two duplicate case values, so the compiler will raise an error.

Multiple choice
  1. 32

  2. 20

  3. 16

  4. Blank Output Screen

  5. Compiler error

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

This is the correct choice because the correct answer is 20, but it will not be printed on the screen because we have used specifier %h in the printf() function which is not recognised by the compiler. To successfully print the output in hexadecimal form on the screen we must use %hx. So, blank output will be there on the screen.

Multiple choice
  1. The result comes out to be: 0111.

  2. The result comes out to be: 1111.

  3. The result comes out to be is: 1000.

  4. The result comes out to be is: 0110.

  5. Compiler error

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

This program will just OR the binary values of 7 and 15. So, after ORing them, the result comes out to be 15 in binary which is 1111. So, this option is correct.

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