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
-
STRING
-
SCALAR
-
Empty Value
-
Not a Reference
C
Correct answer
Explanation
In Perl, the ref function returns an empty string when the variable passed to it is not a reference. Since $val is a plain string scalar, ref($val) evaluates to an empty string ('Empty Value', 596740) rather than throwing an error or returning a label like SCALAR.
-
TRUE
-
MyClass
-
1
-
Object Reference
B
Correct answer
Explanation
In Perl, bless associates a reference with a class, making it an object. The ref() function returns the class name of a blessed reference. Here, an empty hashref {} is blessed into 'MyClass', so ref($val) returns 'MyClass'. TRUE would be from a boolean context, 1 is numeric truth, and 'Object Reference' is not what ref() returns for a blessed object.
-
blah
-
Empty String
-
Can't locate object method "new" via package "B"
-
None of the above
A
Correct answer
Explanation
Package B uses base 'A' to inherit from A, so B->new() calls A's constructor method which blesses an empty hashref. The returned object is a B instance that can call B's foo method, which returns 'blah'. The code prints 'blah' followed by a newline. Options B and C are incorrect because Perl's inheritance works properly and the foo method exists in package B.
-
Compilation error
-
Runtime error
-
No errors
-
Compilation error at statement 2
C
Correct answer
Explanation
This code performs a valid type conversion: an int is cast to float, then the float is assigned to a double. Both conversions are legal - the cast is explicit (int to float), and the float to double conversion is implicit widening. No compilation or runtime errors occur.
-
Compilation error
-
Runtime Error
-
Runtime Exception
-
Output of b is 1
A
Correct answer
Explanation
The variable 'b' is an instance variable (non-static), but main() is a static method. Static methods cannot directly access instance members without creating an object instance first. This causes a compilation error: 'non-static variable b cannot be referenced from a static context.'
-
Compiler error
-
Runtime Exception
-
True
-
False
D
Correct answer
Explanation
When you use 'new Integer(2)', you create distinct Integer objects on the heap. The '' operator compares object references, not values. Since 'a' and 'b' point to different objects, 'ab' returns false. To compare Integer values, use a.equals(b).
-
print([int] 100 )
-
print (Val("100"))
-
iTemp = INTEGER(100)
-
INTEGER iTemp = Val ("100")
D
Correct answer
Explanation
In 4Test (SilkTest's language), to convert a string to an integer, you declare an INTEGER variable and use the Val() function. The syntax 'INTEGER iTemp = Val("100")' correctly declares the variable and converts the string "100" to its numeric value. Options A, B, and C have incorrect syntax for 4Test.
C
Correct answer
Explanation
Setting $#a = 0 truncates the array to only its first element (index 0), removing all other elements. The array @a now contains only one element (0). When an array is assigned to a scalar in Perl, it returns the number of elements in the array, so $size = 1.
-
biggest=Mon Jan 18 19:14:07
-
biggest=0
-
biggest = Mon Jan 18 19:14:07 2038
-
biggest=2038
C
Correct answer
Explanation
The value 0x7FFFFFFF equals 2147483647, which is the maximum value for a signed 32-bit integer representing seconds since the Unix epoch (January 1, 1970). This corresponds to January 18, 2038 at 19:14:07 UTC - the moment of the Year 2038 problem when 32-bit time_t values overflow. The ctime() function formats this as a readable date string.
-
biggest=Mon Jan 18 19:14:07
-
biggest=0
-
biggest = Mon Jan 18 19:14:07 2038
-
biggest=2038
C
Correct answer
Explanation
The value 0x7FFFFFFF equals 2147483647, which is the maximum value for a signed 32-bit integer representing seconds since the Unix epoch (January 1, 1970). This corresponds to January 18, 2038 at 19:14:07 UTC - the moment of the Year 2038 problem when 32-bit time_t values overflow. The ctime() function formats this as a readable date string.
-
print and display
-
display and echo
-
println and display
-
echo and print
D
Correct answer
Explanation
PHP has two primary language constructs for output: 'echo' and 'print'. Both display text, but echo is slightly faster and can take multiple arguments, while print returns a value (always 1) and can only take one argument. 'display' and 'println' are not PHP output functions.
-
NSLog()
-
Printf()
-
System.out.println()
-
Scanf()
A
Correct answer
Explanation
NSLog() is the standard function for logging objects to the console in Objective-C. It works with Objective-C objects and format strings, similar to printf() but specifically designed for Cocoa/Cocoa Touch frameworks. printf() is a C function, System.out.println() is Java, and scanf() is for input.
-
Compilation error
-
Runtime error
-
a being 3.5
-
a being 3
A
Correct answer
Explanation
In Java, 3.5 is a double literal. Assigning a double value to an int variable without explicit casting causes a compilation error because of potential loss of precision. Java requires explicit type conversion like int a = (int)3.5;
-
Compilation error
-
Runtime error
-
Runtime exception
-
No error
D
Correct answer
Explanation
Casting an int value to float and then assigning it to a double is fully legal. The widening conversions (int to float, float to double) occur implicitly or explicitly without data loss, resulting in no compilation or runtime errors.
-
Compilation error: Divisions must be in a try block.
-
Compilation error: DivideByZeroException
-
Runtime Exception - correct answer
-
No Error: a is NaN
C
Correct answer
Explanation
In Java, division of integers by zero evaluates at runtime, throwing an ArithmeticException (a subclass of RuntimeException). It compiles successfully because the compiler does not evaluate division by zero. Java does not have a DivideByZeroException class.