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

  2. 4

  3. Exception

  4. Compilation error

  5. 9

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

The array a has a[1] = {9,2} which is an int array of length 2 (indices 0 and 1). When we try to access b[2] where b = a[1], we're accessing index 2 in an array that only has indices 0 and 1. This causes an ArrayIndexOutOfBoundsException at runtime, not a compilation error (the array sizes are determined at runtime for jagged arrays).

Multiple choice technology programming languages
  1. TRUE

  2. true

  3. FALSE

  4. Compilation Error

  5. Run time Error

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

The code uses assignment (=) not comparison (==). The statement if(var = true) assigns true to var, then evaluates the condition as true, so 'TRUE' is printed. This is a common bug where assignment is mistaken for equality check.

Multiple choice technology programming languages
  1. The element will not be successfully added

  2. ArrayIndexOutOfBounds Exception

  3. The Vector allocates space to accommodate up to 15 elements

  4. Nothing will happen

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

In Java's legacy Vector class, new Vector(5, 10) creates a vector with initial capacity 5 and capacity increment 10. When adding the 6th element exceeds capacity, Vector automatically grows by the increment (10), creating new capacity of 15. This dynamic growth prevents overflow.

Multiple choice technology programming languages
  1. Prints 300 as the output

  2. Prints “C”

  3. Compiler Error

  4. RunTime Error

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

Byte variables in VB.NET have a range of 0-255. When A=200 and B=100 are added, the result is 300, which exceeds the maximum value a Byte can hold. This causes an overflow exception at runtime, not during compilation.

Multiple choice technology programming languages
  1. True

  2. False

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

The code compiles fine. The ArithmeticException is a checked exception that can be thrown in this context. The main method can throw any exception since it's the entry point. The code would compile but would terminate at runtime with the exception, never reaching the println statement. Option A (True) would be the correct answer if the question asked about compilation.

Multiple choice technology programming languages
  1. The output could be 8-1 7-2 8-2 7-1

  2. The output could be 6-1 6-2 5-1 5-2

  3. The output could be 6-1 5-2 6-2 5-1

  4. The output could be 6-1 6-2 5-1 7-1

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

The synchronized keyword on the hit() method ensures that once one thread enters this method, other threads must wait for it to complete before entering. Each thread calls hit() with its unique thread ID, and within hit() the loop prints 'threadId-iteration' twice. Because of synchronization, one thread completes both iterations (6-1 6-2 or 5-1 5-2) before the next thread begins. Option B correctly shows this atomic behavior - all of one thread's output, then all of the other's.

Multiple choice technology programming languages
  1. a=11 b=31

  2. a=10 b=30

  3. a=11 b=30

  4. None of the Above

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

The post-increment operator a++ uses the current value of a (10) in the expression, then increments a to 11. So b = 10 + 20 = 30, and after the expression a becomes 11. The printf outputs a=11 b=30. Option B is wrong because a does change. Option A is wrong because b is 30, not 31.

Multiple choice technology programming languages
  1. core dump

  2. nothing

  3. undefined behavior

  4. all the above

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

In C, calling free(NULL) is explicitly defined to do nothing. The C standard (C99 7.20.3.2) states that if ptr is a null pointer, no action occurs. It does NOT cause a core dump or undefined behavior. This is different from freeing an already-freed pointer or freeing unallocated memory, which are undefined. Option B is correct - 'nothing' happens.

Multiple choice technology programming languages
  1. 3

  2. 5

  3. 7

  4. 6

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

The key is understanding if-statement scope: only the immediately following statement is controlled by the if. int i = 3; if (!i) i++; - !3 is 0 (false), so i++ doesn't execute. i++; now executes (unconditional), i becomes 4. if (i==3) i+=2; - 4 != 3 (false), so i+=2 doesn't execute. i+=2; now executes (unconditional), i becomes 6. printf prints 6. Option D is correct.

Multiple choice technology programming languages
  1. Results in x having the value 1.

  2. Causes a compiler error.

  3. Will require a cast (byte) before 1.

  4. Will give syntax error.

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

In Java, compound assignment operators such as += automatically cast the result of the operation back to the type of the left-hand variable. Therefore, x += 1 is evaluated as x = (byte)(x + 1). This compiles successfully without needing an explicit cast, resulting in x having the value 1.

Multiple choice technology programming languages
  1. The output is 0

  2. Will give compile error

  3. Will give runtime error

  4. The output is 1

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

The final instance variable j is not initialized at declaration, in an instance initializer block, or within any constructor. In Java, all uninitialized final instance variables cause a compile-time error. This prevents the code from compiling, making options claiming successful execution or runtime errors incorrect.