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

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. 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.

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

Non-static variable b cannot be referenced from a static context (main method). Attempting to access it directly without creating an instance of class A causes a compilation error. Runtime options are incorrect because compilation fails first.

Multiple choice java
  1. ten times

  2. zero times

  3. one to nine times

  4. more than ten times

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

The do-while loop executes at least once, then checks the condition. Initially x=10, after first iteration x=9. The condition 'x < 10' is true (9<10), so the loop continues. This creates an infinite loop - it will execute more than ten times until manually stopped or the program crashes.

Multiple choice java
  1. 5,6

  2. 5,5

  3. 6,5

  4. 6,6

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

To solve this question, the user needs to understand the logic of the do-while loop and the post/pre-increment and decrement operators.

The given code initializes two integer variables x and y to 0 and 10, respectively. Then, it enters a do-while loop with the condition x &lt; 5. Inside the loop, the value of y is decremented by 1, and the value of x is incremented by 1. This process continues until the value of x becomes greater than or equal to 5. Finally, it prints the values of x and y.

Now, let's go through each option and explain why it is right or wrong:

A. 5,6: This option is incorrect because the loop stops when the value of x becomes 5, at which point y is equal to 5, not 6.

B. 5,5: This option is correct. The loop stops when the value of x becomes 5, at which point y is also equal to 5.

C. 6,5: This option is incorrect because the loop stops when the value of x becomes 5, at which point x is equal to 5, not 6.

D. 6,6: This option is incorrect because the loop stops when the value of x becomes 5, at which point x is equal to 5, and y is equal to 5.

Therefore, the correct answer is:

The Answer is: B

Multiple choice java
  1. three

  2. other

  3. Compilation Fails

  4. Exception

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

The expression sums two Integer objects by auto-unboxing them to primitive values (1 + 2 = 3), which is then boxed to Integer i. The switch statement auto-unboxes i to match case 3, printing 'three'. Distractors claiming compilation failure or runtime exceptions are incorrect.

Multiple choice java
  1. Compilation fails

  2. An exception is thrown at runtime

  3. The variable first is set to null

  4. The variable first is set to elements[0]

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

The array has 3 elements, so elements.length > 0 is true. The ternary operator returns elements[0] which is 'for'. Option A and B are incorrect because there's no compilation error or exception. Option C is incorrect because first is not set to null.

Multiple choice java
  1. 0

  2. 10

  3. 12

  4. print statement never be executed

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

To solve this question, the user needs to know about while loop and comparison operators.

In the given code snippet, the while loop will only execute if the condition inside the parentheses is true. The code initializes the variable x to 12 and checks if it is less than 10. Since 12 is greater than 10, the condition is false, and the code inside the while loop will never execute. The print statement will execute outside of the loop, which will output the value of the variable x.

Options A, B, and C can be eliminated since none of them represent the correct value.

Option D is incorrect because the print statement will execute regardless of whether the while loop is executed or not.

Therefore, the correct answer is:

The Answer is: C. 12

Multiple choice java
  1. a b

  2. b c

  3. a b c

  4. Compilation fails

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

Java command line arguments passed to the main method do not include the class name itself, so yahoo contains ["a", "b", "c"]. The loop starts at index 1 (x = 1), skipping yahoo[0] ("a"), thus printing yahoo[1] ("b") and yahoo[2] ("c") separated by spaces.

Multiple choice java
  1. null

  2. zero

  3. some

  4. Compilation fails

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

To solve this question, the user needs to know that the given code is testing whether a string value is null or empty. They also need to know the syntax of if-else statements in Java.

Now, let's go through each option and explain why it is right or wrong:

A. null: This option is incorrect because the code checks if the string is null using the expression str == null, which evaluates to false since str is "null" (a non-null string literal).

B. zero: This option is incorrect because the code does not check if the string is empty using the expression str.length() == 0. Instead, it tries to use an invalid syntax by placing an else block after the if block. This leads to a compilation error.

C. some: This option is incorrect because the code won't reach this block due to the compilation error mentioned above.

D. Compilation fails: This option is correct. The code will fail to compile due to the invalid syntax in the else block. The correct syntax for an if-else statement is:

if (condition) {
    // code block for true case
} else {
    // code block for false case
}

Therefore, the correct code should be:

public static void main(String[] args) {
  String str = "null"; 
  if (str == null) {
    System.out.println("null");
  } else if (str.length() == 0) {
    System.out.println("zero");
  } else {
    System.out.println("some");
  }  
}

The Answer is: D

Multiple choice java
  1. Compilation fails

  2. An exception is thrown at runtime

  3. The variable first is set to null

  4. The variable first is set to elements[0]

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

The array elements is initialized with three items, so its length is 3, which is greater than 0. The ternary operator evaluates the condition elements.length &gt; 0 as true, so it assigns elements[0] to the variable first. No exceptions or compilation errors occur.