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

Multiple choice technology programming languages
  1. TRUE

  2. MyClass

  3. 1

  4. Object Reference

Reveal answer Fill a bubble to check yourself
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.

Multiple choice technology programming languages
  1. blah

  2. Empty String

  3. Can't locate object method "new" via package "B"

  4. None of the above

Reveal answer Fill a bubble to check yourself
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.

Multiple choice technology programming languages
  1. Compilation error

  2. Runtime error

  3. No errors

  4. Compilation error at statement 2

Reveal answer Fill a bubble to check yourself
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.

Multiple choice technology programming languages
  1. Compilation error

  2. Runtime Error

  3. Runtime Exception

  4. Output of b is 1

Reveal answer Fill a bubble to check yourself
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.'

Multiple choice technology programming languages
  1. Compiler error

  2. Runtime Exception

  3. True

  4. False

Reveal answer Fill a bubble to check yourself
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).

Multiple choice technology testing
  1. print([int] 100 )

  2. print (Val("100"))

  3. iTemp = INTEGER(100)

  4. INTEGER iTemp = Val ("100")

Reveal answer Fill a bubble to check yourself
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.

Multiple choice technology programming languages
  1. undef

  2. 0

  3. 1

  4. 2

Reveal answer Fill a bubble to check yourself
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.

Multiple choice technology
  1. biggest=Mon Jan 18 19:14:07

  2. biggest=0

  3. biggest = Mon Jan 18 19:14:07 2038

  4. biggest=2038

Reveal answer Fill a bubble to check yourself
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.

Multiple choice technology
  1. biggest=Mon Jan 18 19:14:07

  2. biggest=0

  3. biggest = Mon Jan 18 19:14:07 2038

  4. biggest=2038

Reveal answer Fill a bubble to check yourself
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.

Multiple choice technology programming languages
  1. print and display

  2. display and echo

  3. println and display

  4. echo and print

Reveal answer Fill a bubble to check yourself
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.

Multiple choice technology
  1. NSLog()

  2. Printf()

  3. System.out.println()

  4. Scanf()

Reveal answer Fill a bubble to check yourself
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.

Multiple choice technology programming languages
  1. Compilation error

  2. Runtime error

  3. a being 3.5

  4. a being 3

Reveal answer Fill a bubble to check yourself
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;

Multiple choice technology programming languages
  1. Compilation error: Divisions must be in a try block.

  2. Compilation error: DivideByZeroException

  3. Runtime Exception - correct answer

  4. No Error: a is NaN

Reveal answer Fill a bubble to check yourself
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.