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. 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 technology programming languages
  1. Infinite loop

  2. Until Stack Underflow

  3. Until Machine Hangs

  4. Stack Overflow

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

This code creates infinite recursion by calling main() from within mainn(), which in turn calls main() again. Each call adds a new stack frame without ever returning, eventually consuming all available stack space and causing stack overflow. The loop continues until the stack memory is exhausted, not underflow or machine hang.

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.

Multiple choice technology programming languages
  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

Command-line arguments: args[0]=a, args[1]=b, args[2]=c. The loop starts at x=1, so it prints args[1]=b and args[2]=c with spaces. Index 0 (a) is skipped. Output is b c.

Multiple choice technology programming languages
  1. null

  2. zero

  3. some

  4. Compilation fails

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

The code has syntax error: else if (str.length() == 0) is missing the if keyword. It should be else if (str.length() == 0) not else (str.length() == 0). This causes compilation failure.

Multiple choice technology web 2.0
  1. echo

  2. print_r

  3. display

  4. all the above

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

The print_r function formats and outputs human-readable information about a variable, including complex structures like arrays. Using echo directly on an array produces an Array-to-string conversion notice and prints only the word 'Array'.