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
    • 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. There will be a memory overwrite.

  2. There will be a memory leak.

  3. There will be a segmentation fault.

  4. Not enough space is allocated by the malloc.

  5. It will not compile.

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

Initially, ptr2 points to dynamically allocated memory from malloc(5). The next statement reassigns ptr2 to point to ptr1, causing the reference to the original heap allocation to be lost without being freed, resulting in a classic memory leak.

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.

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.