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
-
windowMoved()
-
windowClosing()
-
windowIconified()
-
windowActivated()
-
windowDeiconified()
-
FocusEvent
-
ComponentEvent
-
AdjustmentEvent
-
WindowEvent
-
ExceptionEvent
E
Correct answer
Explanation
This is the correct choice.
-
1,2,_ _ _ 10
-
an infinite loop
-
1,2,3 _ _ _ 9
-
error in code
B
Correct answer
Explanation
The while loop condition is followed by a semicolon, creating an empty loop body. Since icount is initialized to 1 and never incremented within the loop, the condition (icount < 10) remains true forever. The program enters an infinite loop and never reaches the printf statement.
-
ONE AND HALF
-
TWO
-
FOUR
-
error in code
D
Correct answer
Explanation
Switch statement case labels must be integer constant expressions, not floating-point values. The value 1.5 is a floating-point literal, which violates C syntax rules for case labels. This causes a compilation error.
-
10 10 10
-
10 10 0
-
3 10 10
-
error in code
B
Correct answer
Explanation
In the statement y=x=10, assignment is right-associative so x becomes 10, then y becomes 10. The expression z=x<10 compares 10 with 10, which is false (0). The printf outputs x=10, y=10, z=0.
-
1 2 3 4 5
-
2000 2002 2004 2006 2008
-
10 20 30 40 50
-
error in code
C
Correct answer
Explanation
The expression *(b+i) is pointer arithmetic equivalent to b[i]. As i iterates from 0 to 4, this accesses each element of array b sequentially. The array contains 10, 20, 30, 40, 50, which are printed in order.
-
number is even
-
number is odd
-
displays nothing
-
error in code
-
VALUE_ERROR
-
NO_DATA_FOUND
-
INVALID_NUMBER
-
PROGRAM_ERROR
C
Correct answer
Explanation
INVALID_NUMBER is raised when the conversion of a number to a character string fails.
-
free() fails
-
I Love You
-
malloc() fails
-
strcpy() fails
C
Correct answer
Explanation
Evaluating z = x++ - --y * b / a with x=5, y=-10, a=4, b=2: --y makes y=-11, so the expression is 5 - (-11 * 2 / 4) = 5 - (-22 / 4) = 5 - (-5) = 10. Note: integer division -22/4 = -5 (truncated toward zero). x++ is post-increment, so 5 is used.
B
Correct answer
Explanation
The function fun() increments the pointer by 3 (ptr+=3), advancing it from 'Hello' to point at 'lo'. This pointer is returned to main() where it's printed. String 'Hello' has indices 0-4 for H,e,l,l,o, so +3 points to index 3 which is 'l', making the string 'lo'.
-
22 10 11 13
-
22 11 11 11
-
22 10 11 13
-
22 13 13 13
D
Correct answer
Explanation
In printf, arguments are evaluated right-to-left. Starting with a=10: a++ makes a=11 (but evaluates to 10 in first operation), then ++a makes a=12 (evaluates to 12). So b=10+12=22. For printf: ++a makes a=13, then a is 13, then a++ evaluates to 13 (a becomes 14), and b is 22. Output: 22 13 13 13.
D
Correct answer
Explanation
Operator precedence matters: division happens before addition/subtraction. strlen("Blue")=4, strlen("Purple")=6, strlen("Red")=3, strlen("Green")=5. So: 4 + 6/3 - 5 = 4 + 2 - 5 = 1.
-
1234 1234
-
1234 01234
-
1234 668
-
1234 688
C
Correct answer
Explanation
In C, numbers starting with 0 are octal (base-8). So 01234 is octal, not decimal. Converting 01234 from octal to decimal: 1*8^3 + 2*8^2 + 3*8 + 4 = 512 + 128 + 24 + 4 = 668. Therefore, printf outputs: 1234 668.
-
System Hangs
-
100 100
-
0 100
-
1 100
A
Correct answer
Explanation
The outer for loop has no condition (empty middle clause), so it's infinite: for(i=0;;i++). The inner loop is also infinite: for(j=0;;j++). The break only exits the inner loop when j>100, but then the inner loop restarts with j=0. This continues forever, causing the system to hang.