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. Error: anar is referenced before it is initialized

  2. null

  3. 0

  4. 5

Reveal answer Fill a bubble to check yourself
C Correct answer
Explanation

In Java, when you create a new int array, all elements are automatically initialized to 0. The code creates an int array of size 5 and prints the first element anar[0], which will be 0.

Multiple choice technology programming languages
  1. default

  2. default, zero

  3. error default clause not defined

  4. no output displayed

Reveal answer Fill a bubble to check yourself
B Correct answer
Explanation

Since i is 9, it matches no explicit case, transferring control to the default block. Because there is no break statement at the end of the default block, execution falls through to execute case 0 print statement, outputting both 'default' and 'zero'.

Multiple choice technology programming languages
  1. System.out.println(Math.floor(-4.7));

  2. System.out.println(Math.round(-4.7));

  3. System.out.println(Math.ceil(-4.7));

  4. System.out.println(Math.min(-4.7));

Reveal answer Fill a bubble to check yourself
C Correct answer
Explanation

To solve this question, the user needs to understand the difference between the Math.floor(), Math.round(), Math.ceil(), and Math.min() methods in Java.

  • Math.floor() returns the largest (closest to positive infinity) double value that is less than or equal to the argument and is equal to a mathematical integer.
  • Math.round() returns the closest long or int, as given by the methods of the same name, to the argument, with ties rounding to positive infinity.
  • Math.ceil() returns the smallest (closest to negative infinity) double value that is greater than or equal to the argument and is equal to a mathematical integer.
  • Math.min() returns the smaller of two double values as an argument.

Now, let's go through each option and determine which one will output -4.0:

A. System.out.println(Math.floor(-4.7));

  • This option will output -5.0 because Math.floor() returns the largest double value that is less than or equal to the argument, which in this case is -5.0.

B. System.out.println(Math.round(-4.7));

  • This option will output -5 because Math.round() returns the closest long or int to the argument, which in this case is -5.

C. System.out.println(Math.ceil(-4.7));

  • This option will output -4.0 because Math.ceil() returns the smallest double value that is greater than or equal to the argument, which in this case is -4.0.

D. System.out.println(Math.min(-4.7));

  • This option will not compile because Math.min() requires two arguments, and only one is given.

Therefore, the answer is:

The Answer is: C

Multiple choice technology programming languages
  1. Bic

  2. ic

  3. icy

  4. error: no method matching substring(int,char)

Reveal answer Fill a bubble to check yourself
B Correct answer
Explanation

The substring method in Java is substring(int beginIndex, int endIndex). With beginIndex=1 and endIndex=3, it extracts characters from index 1 (inclusive) to index 3 (exclusive). From 'Bicycle', this gives 'ic' (characters at positions 1 and 2).

Multiple choice technology programming languages
  1. 0

  2. 1

  3. 2

  4. -1

Reveal answer Fill a bubble to check yourself
A Correct answer
Explanation

To solve this question, the user needs to understand the basic concept of a do-while loop in Java. The loop executes the code block at least once, even if the condition is initially false. The user must evaluate the code block inside the loop to determine what value is assigned to the variable i and printed to the console.

In this code, the loop decrements the value of i by 1 until i is no longer greater than 2. Since i is initially 1, it will be decremented to 0 before the condition fails and the loop ends. Therefore, the correct answer is:

The Answer is: A. 0

Multiple choice technology programming languages
  1. DrScheme

  2. Sh

  3. Error : string-set! accepts 1 argument, given 3

  4. Error: string-set!: expects type <mutable string> as 1st argument, given "DrScheme"

Reveal answer Fill a bubble to check yourself
D Correct answer
Explanation

string-set! modifies a string character in-place. However, string literals like "DrScheme" are immutable (cannot be changed). The function expects a mutable string, but a string literal is immutable. Hence the error about expecting a mutable string.

Multiple choice technology programming languages
  1. name

  2. 0

  3. empty string.

  4. none

Reveal answer Fill a bubble to check yourself
C Correct answer
Explanation

The loop copies characters from p1 to p2 until the null terminator. However, p2 continues incrementing past the copied string. After the loop, p2 points AFTER the null terminator, so printf prints an empty string. The copy succeeded, but p2 no longer points to the beginning.

Multiple choice technology programming languages
  1. Cisco System

  2. isco Systems

  3. Cisco Systems

  4. Cisco

Reveal answer Fill a bubble to check yourself
B Correct answer
Explanation

To solve this question, the user needs to understand how pointers work in C and the order of operations in the given code.

Initially, ptr points to the first character of the string "Cisco Systems".

The expression *ptr++ increments the pointer ptr to point to the next character, but dereferences the original pointer to get the value of the first character. Therefore, this operation has no effect on the value of ptr.

The expression ptr++ increments the pointer again, so that it now points to the second character of the string.

Finally, the printf function is called, which outputs the string starting from the second character.

Therefore, the correct answer is:

The Answer is: B. isco Systems

Multiple choice technology mainframe
  1. Run time error

  2. Compilation error

  3. 10

  4. -10

Reveal answer Fill a bubble to check yourself
C Correct answer
Explanation

Subtracting 20 from a PICTURE 99 variable (unsigned, holding 10) results in -10. Since the picture clause lacks a sign identifier 'S' (it is PIC 99, not PIC S99), the negative sign is dropped, leaving the value as unsigned 10. Thus, the resultant value of X remains 10.

Multiple choice technology programming languages
  1. BA

  2. AB

  3. Compilation Error

  4. Null point reference error

Reveal answer Fill a bubble to check yourself
A Correct answer
Explanation

Perl's destructor (DESTROY) uses reverse order of inheritance. When $obj is destroyed, B's DESTROY runs first (prints 'B'), then it reblesses itself to class A. Then A's DESTROY runs (prints 'A'). The output is 'BA'. No compilation or runtime errors occur.