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 softskills creativity
  1. Nothing

  2. 3

  3. 1

  4. 2

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

The while(1); statement is an infinite loop - the semicolon makes it an empty statement that repeats forever. The lines c++ and printf are unreachable code that never executes. The program hangs in the infinite loop, producing no output. This is a classic unreachable code scenario.

Multiple choice softskills creativity
  1. 3.4141

  2. 3.41426

  3. 3.414164

  4. 3.4142

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

The format specifier %0.4f means print with 4 decimal places. Standard rounding applies: 3.414164 rounded to 4 places looks at the 5th digit (6), which rounds the 4th digit up from 1 to 2. Therefore 3.4142 is printed. Options A, B, and C are incorrect because they either truncate or round incorrectly.

Multiple choice softskills creativity
  1. 12345

  2. 1234

  3. 123

  4. 1

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

The do-while executes once with i=1, printing 1 and incrementing i to 2. The if(i<15) condition is true, so continue jumps back to loop condition. The while(false) condition fails, terminating the loop. Only 1 is printed. The continue statement affects loop control but the false condition guarantees single execution.

Multiple choice softskills creativity
  1. 1212

  2. 121.2

  3. 12f(1,2)

  4. 12f(12)

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

The macro f(a,b) uses ## (token pasting) to concatenate 1 and 2 into 12. Macro h(a) calls g(a) which stringifies with #a. So h(f(1,2)) becomes g(12) then f(1,2) as string literal. The first printf outputs f(1,2). The second printf calls g(f(1,2)) directly, which stringifies to 12. Output: f(1,2)12.

Multiple choice softskills creativity
  1. >5=-15

  2. <5=-15

  3. <5=15

  4. >5=15

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

When mixing signed and unsigned integers, C promotes the signed value to unsigned. -20 becomes a very large positive number (2^32-20 for 32-bit int). i+j (5 + large unsigned) exceeds 5, so the if condition is true. The printf uses %d to format j+i, which is -15 when viewed as signed. Option A is correct: >5=-15.

Multiple choice softskills creativity
  1. 123

  2. 6123

  3. 1236

  4. 3216

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

Function argument evaluation order in C is unspecified (typically right-to-left). The call sum(a(),b(),c()) evaluates c() first (prints 3), then b() (prints 2), then a() (prints 1). sum() adds 1+2+3=6, which printf prints. Output: 3216. The return values are used in the sum, not the print order.

Multiple choice softskills creativity
  1. HP-UX-HewlettPack

  2. Error

  3. HP-UX_HewlettPack

  4. none

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

C function names cannot contain hyphens. The identifier OS_HP-UX_print is interpreted as OS_HP minus UX_print, which is invalid syntax. This causes a compilation error. Option A would be valid if the function were named OS_HP_UX_print with underscores. Hyphens are subtraction operators, not valid identifier characters.

Multiple choice softskills creativity
  1. 1243

  2. 4321

  3. 1234

  4. 4312

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

printf returns the number of characters printed. Working outward: innermost printf("%d",i) prints 43 and returns 2. Middle printf("%d",2) prints 2 and returns 1. Outermost printf("%d",1) prints 1 and returns 1. The printed characters appear left-to-right: 4321. Option B correctly shows this output.

Multiple choice softskills creativity
  1. Today is Aug 2, 201012

  2. Today is Aug 2, 2010

  3. Today is 12

  4. None

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

The code formats the current date and appends the integer 12. If the date was Aug 2, 2010, the output 'Today is Aug 2, 201012' is produced because System.out.print does not add spaces or newlines between the date string and the integer.

Multiple choice softskills creativity
  1. 12

  2. nothing

  3. compilation error

  4. 0

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

The code contains several errors: 'NowString()' is a constructor name that doesn't match the class 'NowS', and 'Super.Sam(12)' is invalid syntax for calling a superclass constructor (it should be 'super(12)'). These issues cause a compilation error.

Multiple choice softskills creativity
  1. Run-time Error

  2. True

  3. Compilation Error

  4. False

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

The code uses assignment (=) instead of equality (). In 'if(var = true)', the assignment happens first (var becomes true), then the condition evaluates the assigned value. Since true is truthy, the if-block executes, printing 'TRUE'. This is a common bug - the programmer likely meant to compare () but accidentally assigned. There's no compilation or runtime error - Java allows boolean assignment in conditions.