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
-
Compile-Time error
-
2.00
-
%.2
-
2.000000
C
Correct answer
Explanation
The format string "%.2" is incomplete - it lacks a type specifier like 'f' for float. In C, this is undefined behavior, but many implementations will simply print the format string literally when it's invalid, resulting in "%.2" as output. This is a common trick question testing knowledge of proper printf format syntax.
-
Compile-Time Error
-
Run-Time Error
-
11
-
None of above
C
Correct answer
Explanation
The semicolon ';' is a statement terminator in C, not an operator. Having two semicolons 'int b=6;;' is valid - the second semicolon just creates an empty statement. The program correctly computes c = 5 + 6 = 11 and prints it.
A
Correct answer
Explanation
The nested loops iterate i from 1-3 and j from 1-2. When i==j (i=1,j=1), continue skips to next j. For i=2, j=2: j%3=2 > 1 is false (2 is not > 1), so no break. printf prints '2'. For i=3, j=1: j%3=1 is not > 1, printf prints '3'. Output: 2,3.
-
a=5 b=6
-
a=6 b=5
-
a=6 b=0
-
None of the above
C
Correct answer
Explanation
The swap macro expands to multiple statements separated by semicolons, not a single compound statement. Without braces, only 'temp=a' executes conditionally. Since 5 > 6 is false, the entire block is skipped. temp is static and initialized to 0 by default. printf outputs 'a=6 b=0' because 'a=b; b=temp;' execute unconditionally after the if block.
-
Compile-Time error
-
5 -6
-
5 65530
-
none of the above
C
Correct answer
Explanation
val=5 is unsigned int (typically 16-bit range 0-65535). val-11 = 5-11 = -6, which wraps around to 65530 (65535-6+1). The %u format prints unsigned values, so output is 5 65530. Option A is wrong - no compile error. Option B shows signed behavior which %u won't display.
-
Compile-Time error
-
Run-Time Error
-
24
-
Unpredictable
C
Correct answer
Explanation
*&z is a pointer dereference of z's address, which just gives z. *&z *= *&x * *&y becomes z *= x * y, or z = 2 * 4 * 3 = 24. The *& operators cancel out - & takes address, * dereferences it. This is a pointer trick question testing understanding of address and dereference operators.
-
Compile-Time Error
-
i=1680 j=1680
-
i=629 j=6561
-
i=1681 j=3024
-
Compile-Time Error
-
10 9 8 7 6
-
9 8 7 6 6
-
10 8 7 6 6
-
Compile-Time Error
-
5
-
Unpredictable
-
No output
C
Correct answer
Explanation
The printf function expects a matching argument for its format specifier, but none is provided. This leads to undefined behavior, meaning the output is unpredictable.
-
Compile time error
-
5
-
6
-
Unpredictable
D
Correct answer
Explanation
Since printf has a format specifier but no arguments supplied, it reads from the stack or registers in an undefined manner, yielding unpredictable output rather than a compile error.
-
Compile-Time Error
-
5 6 7
-
7 6 5
-
Unpredictable
D
Correct answer
Explanation
With three format specifiers and zero arguments passed to printf, the function attempts to read missing values from the stack, resulting in unpredictable output.
A
Correct answer
Explanation
In C++, modifying a variable twice without an intervening sequence point causes undefined behavior. Here c++ both modifies c and yields its original value, but there's no sequence point between the two c evaluations in the cout statement. This violates sequencing rules, making the output undefined rather than predictably 01, 00, or 10.
-
Outputs 12
-
Outputs 10
-
Outputs the address of v
-
Undefined
B
Correct answer
Explanation
In main, v is initialized to 10. Its address is passed to afunction. Inside afunction, the local pointer parameter x is reassigned to point to a newly allocated memory address, leaving the original variable v in main completely unmodified. Thus, v remains 10.