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 fails with an error at line 4

  2. Compilation fails with an error at line 3

  3. true

  4. false

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

In Java, arrays are objects. Therefore, any array instance is an instance of Object, and the expression index instanceof Object correctly evaluates to true at runtime.

Multiple choice technology programming languages
  1. A

  2. Compilation fails with an error at line 4

  3. B

  4. Compilation fails with an error at line 8

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

This demonstrates Java polymorphism and instanceof operator. A b = new B() creates a B object but assigns it to A reference. The instanceof check (a instanceof B) returns true because the actual object is B. The cast ((B)a) is safe, and B's printValue() method executes, printing 'B'. This is runtime polymorphism in action.

Multiple choice technology programming languages
  1. Compilation fails with an error at line 5

  2. Compilation fails with an error at line 8

  3. 17

  4. 0

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

The static method add() attempts to access non-static instance variables i and j directly. In Java, static methods cannot access instance variables without an object reference, causing a compilation error at line 8.

Multiple choice technology programming languages
  1. x = 0; y = 1984

  2. x = 2001; y = 1984

  3. x = 2001; y = 0

  4. x = 1984; y = 2001

  5. x = 0; y = 0

  6. Error

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

Java evaluates operands left-to-right. The statement x ^= y ^= x ^= y; is evaluated as x ^= (y ^= (x ^= y)). The initial value of x (1984) is loaded first for the outermost assignment. The innermost x ^= y sets x to 1984 ^ 2001. The middle y ^= x sets y to 2001 ^ (1984 ^ 2001) = 1984. Finally, the outer x ^= y sets x to 1984 ^ 1984 = 0.

Multiple choice technology programming languages
  1. Hello world

  2. Won't even Compile

  3. Run time error

  4. None of these

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

The code contains a JavaDoc comment block in the middle of executable code. Java comments cannot appear between method declarations without proper placement - this violates Java syntax rules and prevents compilation.

Multiple choice technology programming languages
  1. Compilation Error

  2. iexplore::maximize

  3. Runtime Error

  4. None of these

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

The code compiles because 'http:' is treated as a label and '//www.google.com' is a comment. The program prints 'iexplore:' (without newline), then ':maximize' (with newline), resulting in 'iexplore::maximize'. The double colon appears from the printed text and the label.

Multiple choice technology programming languages
  1. Hello world!

  2. Throw a NullPointerException

  3. Won't even compile

  4. Run time error

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

Static methods in Java can be called on a null reference without throwing NullPointerException. The JVM resolves the method call based on the declared type (Null class), not the actual object reference (null). This is a subtle Java behavior often tested in interviews.

Multiple choice technology programming languages
  1. Exception

  2. Stack Overflow

  3. 2

  4. 1

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

In Java, an IdentityHashMap uses reference equality (==) rather than object equality (equals()) for keys. Since the two string literals "Mickey" are interned, they refer to the exact same string object in memory. Therefore, the second put operation overwrites the first, resulting in a size of 1.

Multiple choice technology web technology
  1. somerar is 15

  2. somerar is 16

  3. somerar is 1

  4. error in code

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

To solve this question, the user needs to understand the concept of global variables and function in PHP. The script defines a global variable named $somevar with a value of 15, and a function named addit() that increments the value of $somevar by one and then outputs its new value. The function explicitly states the variable is global using the global keyword.

When the addit() function is called, it will first increment the value of $somevar by one, resulting in a value of 16. Then, the function will output the string "somerar is 16" using the echo statement.

Therefore, the correct answer is:

The Answer is: B. somerar is 16

Multiple choice technology programming languages
  1. The program has a syntax error.

  2. The program has a runtime error.

  3. The program runs fine, but displays nothing.

  4. The program runs fine and displays It is even!.

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

The expression even = true is an assignment operator, not a comparison operator (==). It assigns true to even and evaluates to true, causing the if statement block to execute and print It is even!.

Multiple choice technology programming languages
  1. The program cannot compile because you cannot have the print statement in a non-void method

  2. The program cannot compile because the compiler cannot determine which max method should be invoked

  3. The program runs and prints 2 followed by "max(int, double)" is invoked.

  4. The program runs and prints 2 followed by "max(double, int)" is invoked.

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

The call max(1, 2) passes two int literals. Java's overload resolution requires finding the most specific method. The two overloaded methods are max(int, double) and max(double, int). To call either, one int must be promoted to double. Both conversions are equally applicable, creating ambiguity. The compiler cannot determine which method to invoke, so compilation fails.

Multiple choice technology programming languages
  1. 5

  2. 6

  3. 7

  4. 8

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

The do-while loop executes at least once. Iteration 1: item becomes 1, sum becomes 1. Iteration 2: item becomes 2, sum becomes 3. Iteration 3: item becomes 3, sum becomes 6. Now sum > 4, so break executes. Loop terminates. Final sum is 6.

Multiple choice technology programming languages
  1. 0x22ff74

  2. 0x22ff70

  3. 0x22ff73

  4. Compiler error

  5. 19

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

Pointer arithmetic scales by the size of the pointed-to type. On a 32-bit system, int is typically 4 bytes. When you subtract 1 from an int pointer, it decreases by 4 bytes (not 1 byte). So if ptr points to 0x22ff74, ptr-1 points to 0x22ff70. This is a fundamental property of pointer arithmetic in C/C++.