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. Size of c: some value Addr of c:some address

  2. Size of c: some value Addr of c:some value

  3. Size of c: some address Addr of c:some address

  4. Compilation error

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

In modern C standards, defining main() without an explicit return type (such as int) results in a compilation error. Distractors are incorrect because the compiler will fail to build the program before it can execute and output any size or address values.

Multiple choice technology programming languages
  1. -

  2. -c

  3. -c2

  4. -2c

  5. -c22b

  6. -2c2b

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

s starts as "-". s1() calls s2(). s2() calls s3() which throws Exception immediately. The statements s += "2" in s2() never execute. s1() catches the exception and executes s += "c". Final value: "-c".

Multiple choice technology programming languages
  1. for(int y : x) {

  2. for(x : int y) {

  3. int y = 0; for(y : x) {

  4. for(int y=0, z=0; z<x.length; z++) { y = x[z];

  5. for(int y=0, int z=0; z<x.length; z++) { y = x[z];

  6. int y = 0; for(int z=0; z<x.length; z++) { y = x[z];

Reveal answer Fill a bubble to check yourself
A,D,F Correct answer
Explanation

A is correct for-each syntax. D is valid - declares y=0, z=0 then iterates. F is valid - y declared outside, z declared in loop. B has wrong order. C declares y in initialization which isn't allowed. E incorrectly declares int z in initialization.

Multiple choice technology programming languages
  1. 1 3 9

  2. 5 5 7 7

  3. 1 3 3 9 9

  4. 1 1 3 3 9 9

  5. 1 1 1 3 3 3 9 9 9

  6. Compilation fails

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

For x=1,3: prints twice each. For x=5,7: continue outer loop skips them. For x=9: prints twice. The inner loop prints x on j=0, breaks on j=1. Output: 1 1 3 3 9 9 (12 characters with spaces).

Multiple choice technology programming languages
  1. 0 1 2 3

  2. 1 1 1 3 3

  3. 0 1 1 1 2 3 3

  4. 1 1 1 3 3 4 4 4

  5. 0 1 1 1 2 3 3 4 4 4

  6. compilation fails

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

j=0: prints 0, breaks inner. j=1: prints 1 1 1 (no break triggered). j=2: prints 2, breaks inner. j=3: prints 3 3 then breaks foreach. Output: 0 1 1 1 2 3 3.

Multiple choice technology programming languages
  1. empty string

  2. value

  3. the code will fail

  4. None of the above

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

The code fails because init() is called before bless() returns a fully constructed object. When init() attempts $self->{key} = 'value', $self is still an unblessed hash reference (not yet an object of class A), but more critically, calling init() inside new() before the bless completes means $self lacks proper object context. Perl's bless() operation must complete before the object can properly call its own methods. The correct pattern is to bless first, then initialize, or use a post-bless initialization hook.

Multiple choice technology programming languages
  1. 2

  2. 6

  3. 106

  4. I don't like undefs

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

The array @a contains (1, undef, 2). The loop iterates three times: first val=1, foo(1) returns 2, sum becomes 2; second val=undef, foo(undef) dies with error message, eval catches it ($@ is true), so sum += 100 making sum = 102; third val=2, foo(2) returns 4, sum becomes 106. The print outputs 106. The eval block traps the die() on undefined input, adding 100 instead of failing.

Multiple choice technology programming languages
  1. t t1

  2. t1 t

  3. t t

  4. Compilation succeed but Runtime Exception

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

Java thread priorities must be between 1 (MIN_PRIORITY) and 10 (MAX_PRIORITY). The code attempts to set t1's priority to -3, which violates this constraint. This causes an IllegalArgumentException at runtime. The code compiles successfully but crashes during execution.

Multiple choice technology programming languages
  1. good

  2. null

  3. Compilation fails with an error at line 5

  4. Compilation succeed but Runtime Exception

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

The Thread object 't' is named 'good' before starting. When the thread executes, its run() method calls Thread.currentThread().getName(), which returns 'good'. The main thread creates and starts 't' but doesn't print anything itself.

Multiple choice technology programming languages
  1. 59

  2. Compile time error, because you have to do int total = ((Integer)(list.get(0))).intValue();

  3. Compile time error, because can't add primitive type in List.

  4. Compile Properly but Runtime Exception

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

Java's compiler handles autoboxing and unboxing automatically. The primitive int value 59 is autoboxed into an Integer when added to the list, and then automatically unboxed back to an int when retrieved using list.get(0), making the code correct and printing 59 without errors.

Multiple choice technology programming languages
  1. 0

  2. Compile with error

  3. null

  4. NullPointerException

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

The code attempts to unbox a null Integer reference to a primitive int. Unboxing involves calling i.intValue(), which throws NullPointerException when i is null. The exception occurs before any output is produced.