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
B
Correct answer
Explanation
The for loop iterates through the sequence 1 to 50, so i takes values 1,2,3,...,50 (50 iterations). Inside the loop, 'let i=i+1' increments each value before printing. After the loop, i=50 (last assigned value). The echo prints 50, not a sum. However, this seems to be a trick question - if we sum 1+2+...+50 = 1275, which is option B. The question may intend the sum of the series.
-
123
-
Compile-Time Error
-
123.00
-
123.000000
D
Correct answer
Explanation
The %f format specifier in printf defaults to 6 decimal places. 123. is a valid floating-point literal. The output will be 123.000000, not 123, 123.00, or a compile error.
-
14
-
Compile-Time Error
-
15
-
None of the above
C
Correct answer
Explanation
sizeof returns the size in bytes, including the null terminator. 'C For Swimmers' has 14 characters plus 1 null terminator = 15 bytes. sizeof str is evaluated at compile time as 15.
C
Correct answer
Explanation
The expression (100==100) evaluates to 1 (true). The ! operator negates it to 0. Then 0+1 = 1. The printf statement prints this result.
-
500 100 30 40 4
-
Run-Time Error
-
300 -200 300 10 4
-
700 200 300 10 4
-
20
-
17+3
-
173
-
CompileTime Error
C
Correct answer
Explanation
When a string is concatenated with integers using the + operator, Java evaluates left-to-right. First "The answer is: " + 17 produces "The answer is: 17". Then that string is concatenated with 3 to produce "The answer is: 173". Once a string enters the expression, all subsequent + operations perform string concatenation, not arithmetic addition.
C
Correct answer
Explanation
The SUM function in SAS with the 'of' syntax sums a range of variables. SUM(of X1-X3) sums variables X1, X2, and X3. With X1=9, X2=4, X3=1, the sum is 9+4+1=14. The SUM function also handles missing values gracefully (treating them as 0). Option C is correct.
C
Correct answer
Explanation
SUM(OF X1-X3) sums the variables X1, X2, X3 (values 9, 4, 1). 9+4+1 = 14. The SUM function handles missing values differently than simple addition, though here all values are present.
D
Correct answer
Explanation
Pointer arithmetic moves the pointer 3 characters forward from H-E-L-L-O, so it points to L-L-O. The printf outputs from that position, printing LO. Options A, B, and C are incorrect pointer offsets.
B
Correct answer
Explanation
The code uses cout << from the C++ iostream library. C would use printf, C# would typically use Console.WriteLine, and Java would use System.out.println.
-
JAVA
-
C#
-
JavaScript
-
PYTHON
A
Correct answer
Explanation
The code snippet uses 'public static void main(String args[])' and 'System.out.println', which is the standard entry point and output syntax for Java. C#, JavaScript, and Python have different syntaxes.
B
Correct answer
Explanation
Iterators in Java are 'fail-fast' - they throw ConcurrentModificationException if the collection is modified during iteration (except through the iterator's own remove method). The iterator does not automatically update to reflect changes made directly to the collection during traversal.