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 web technology
  1. Green

  2. Red

  3. Either green or red (default color black) will be applied

  4. Error

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

In WPF/XAML, locally set properties always take precedence over styled properties. Even though the Style defines Background as 'Green', the direct Background='Red' setting on the Button element overrides it. This is a fundamental property value precedence rule: inline/local values > style setters > default values. The button will appear red.

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

  2. [,]

  3. ,,*

  4. None of the Above

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

The recursive method exampleprint(1) follows this flow: print '[' then call exampleprint(0) which prints '', then print ',', then call exampleprint(0) again which prints '', then print ']' and newline. Result: [,]

Multiple choice technology programming languages
  1. Compilation of class A fails.

  2. Line 28 prints the value 3 to System.out.

  3. Line 28 prints the value 1 to System.out

  4. A runtime error occurs when line 25 executes

  5. Compilation fails because of an error on line 28

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

Class A fails compilation because the static method getInstanceCount() attempts to access the non-static instance variable counter. Static methods cannot access instance variables directly because they run in a static context without a reference to any specific object instance.

Multiple choice technology programming languages
  1. 234

  2. 334

  3. 2334

  4. 0123456

  5. 01234456

  6. 12334567

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

The regex \d* matches zero or more digits. On string 'ab34ef', it matches: position 0 (empty), position 1 (empty), position 2 (digits '34'), position 4 (empty), position 5 (empty). The code prints m.start() + m.group() for each match: '0' + '' + '1' + '' + '2' + '34' + '4' + '' + '5' + '' = '01234456'. The pattern matches twice at position 4 because after consuming '34', zero-width matches occur at positions 4 and 5.

Multiple choice technology databases
  1. Arrays in Java are essentially objects

  2. It is not possible to assign one array to another. Individual elements of array can however be assigned.

  3. Array elements are indexed from 1 to size of array

  4. If a method tries to access an array element beyond its range, a compile warning is generated.

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

Arrays in Java are objects that inherit from Object class and have a length field. Option B is false because you can assign array references (array1 = array2) - just the reference is copied, not elements. Option C is false because Java arrays are 0-indexed. Option D is false because out-of-range access throws ArrayIndexOutOfBoundsException at runtime, not a compile warning.

Multiple choice technology databases
  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

The compound assignment operator x += 1 is valid for byte type. The result of x += 1 is implicitly cast back to byte, so x will have the value 1. This is a special rule for compound assignment operators - they perform an implicit narrowing primitive conversion. No explicit cast is required, unlike simple assignment which would need (byte)1.

Multiple choice technology databases
  1. float

  2. int

  3. byte

  4. double

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

When mixing numeric types in arithmetic, Java promotes to the widest type involved: float (32-bit) + int (32-bit) + byte (8-bit) results in float. Promotion follows: byte/short/char → int → long → float → double. Since float is present, all operands are promoted to float. The result is NOT double (higher precision) or int (narrower).