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
E
Correct answer
Explanation
This is the correct answer because ~ (tilde) operator is unary operator. So, it can be applied only on a single operand. But here we are using it on two operands (x~a). So, it will generate an error.
-
HelloByeGoodBad
-
ByeGoodBad
-
GoodBad
-
Bad
-
Compiler error
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.
-
0 GoodBad
-
8ByeGoodBad
-
14HelloByeGoodBad
-
16
-
Compiler error
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.
-
32
-
20
-
16
-
Blank Output Screen
-
Compiler error
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.
-
The result comes out to be: 0111.
-
The result comes out to be: 1111.
-
The result comes out to be is: 1000.
-
The result comes out to be is: 0110.
-
Compiler error
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.
-
32
-
20
-
16
-
4
-
Compiler error
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.
-
ByeHello Keep CalmGet Lost
-
Hello Keep CalmGet Lost
-
Keep CalmGet Lost
-
Get Lost
-
Compiler error
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.
-
ByeHelloKeep CalmGet Lost
-
HelloKeep CalmGet Lost
-
Keep CalmGet Lost
-
Get Lost
-
Blank screen
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.
-
Hello Good ByeSee U Later
-
Bye
-
Bye Hello Good Bye See U Later
-
Good ByeSee U Later
-
Error at line 1
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.
-
y = HELLO
-
y = ELLO
-
y = LLO
-
y = LO
-
y = O
int testarray[3][2][2] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12};
What value does testarray[2][1][0] in the sample code above contain?
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.
-
12,10,11,13
-
22,10,11,13
-
22,11,11,11
-
12,11,11,11
-
22,13,13,13
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.
-
1, 2, 3, 4, 5, 5
-
4, 3, 2, 1, 0, 0
-
5, 4, 3, 2, 1, 0
-
0, 0, 1, 2, 3, 4
-
0, 1, 2, 3, 4, 5
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).
-
-
0
-
4
-
4 + sizeof( int )
-
4 * sizeof( int)
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.
-
x = 0
-
x = 1
-
x = 3
-
x = 4
-
x = 5
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.