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 programming languages
  1. X=4 and Y= ‘seven’

  2. X=7 and Y=’seven’

  3. X=7 and Y=’four’

  4. X=4 and Y=’four’

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

In SAS DATA step logic, the assignment statements execute sequentially. When x=4, the condition 'if x=4' is true (using single = for comparison in SAS), so y='four'. The ELSE IF never executes. Later, x is reassigned to 7, but y remains 'four' - the IF/ELSE doesn't re-evaluate. Final values: x=7, y='four'.

Multiple choice technology programming languages
  1. 5 7

  2. 4 7

  3. 5 1

  4. 4 1

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

Due to the short-circuiting behavior of the logical OR (||) operator, the right-hand side i++ && printf(...) is never evaluated because the left operand j (7) is true. As a result, i remains 4, and the expression result of 1 is assigned to j.

Multiple choice technology programming languages
  1. Compilation error-Type mismatch

  2. Hai

  3. Hello

  4. Run time error

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

The float constant 1.1 undergoes precision loss during conversion when assigned to the single-precision float a. The double b retains full double-precision representation. When compared, a is promoted to double, but because the precision values differ, the equality check fails and prints Hello.

Multiple choice technology programming languages
  1. 100010001000

  2. 100010010

  3. 101001000

  4. 010010001

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

C features block scope rules where variables declared in inner blocks shadow outer declarations. The innermost print statement prints the innermost a (1000), the next outer block prints its local a (100), and the outermost block prints the first a (10), resulting in the output string 100010010.

Multiple choice technology programming languages
  1. 10

  2. 11

  3. Compilation error-Null can not be there after for

  4. Infinite loop

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

The for loop has a semicolon immediately after its closing parenthesis, making it an empty loop body. The loop executes from i=0 to i=9, then when i becomes 10, the condition i<10 becomes false and the loop exits. The printf then prints 10, the final value of i.

Multiple choice technology programming languages
  1. 21 1000 21 1002

  2. 21 1000 Garbage_value 1002

  3. 21 1000 22 1002

  4. 21 1000 22 1000

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

The statement ++*k increments the value stored at address k (variable i) to 21, leaving the address unchanged at 1000. Next, (*k)++ increments the value of i again to 22 while keeping k pointing to address 1000. Other options incorrectly modify the pointer address.

Multiple choice technology programming languages
  1. 10

  2. Garbage value

  3. 100

  4. Compilation error

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

The line x = x/p causes a compilation error because / is interpreted as the start of a C comment. The compiler looks for a closing */ but never finds one, resulting in a compilation error. To correctly divide x by the value pointed to by p, parentheses are needed: x = x/(*p).

Multiple choice technology web technology
  1. 6000

  2. 400

  3. 10

  4. Compilation error-Functions can not be defined as macro

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

The preprocessor replaces the macro sum(i,j) textually with i+j without parentheses. The expression becomes i = j * i + j * i. Because multiplication has higher precedence than addition, this evaluates to (20 * 10) + (20 * 10), which simplifies to 200 + 200 = 400.

Multiple choice technology programming languages
  1. 23

  2. Garbage Value

  3. 0

  4. Compilation-Array out of boundary

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

In the C language, compiler specifications do not enforce array boundary checks. Writing to a[7] translates to modifying the memory offset corresponding to that index, and subsequently printing it retrieves the assigned value of 23 without causing a compilation or runtime error.

Multiple choice technology programming languages
  1. i = 3

  2. Compilation fails.

  3. A ClassCastException is thrown at line 6.

  4. A ClassCastException is thrown at line 7.

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

The code compiles and runs successfully. A Foo object is created, upcast to Object type, then downcast back to Foo. Since the actual object is a Foo instance, the downcast succeeds and foo.i is accessible, printing 'i = 3'. This is a valid casting pattern in Java.

Multiple choice technology programming languages
  1. i = 6 and j = 5

  2. i = 5 and j = 6

  3. i = 5 and j = 5

  4. i = 6 and j = 6

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

The do-while loop runs while i < 5. In each iteration, i increments (postfix) and j decrements (prefix). After 4 iterations, i becomes 5 (causing loop exit) and j becomes 6. The continue statement has no effect since it's at the end of the loop body.

Multiple choice technology programming languages
  1. i = 6 and j = 5

  2. i = 5 and j = 5

  3. i = 5 and j = 6

  4. i = 6 and j = 4

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

In the do-while loop, j decrements each iteration. When i increments to 5 (via ++i in the while condition check), ++i < 5 becomes 5 < 5 (false), terminating the loop. At this point, j has decremented four times from 10 to 6, yielding i = 5 and j = 6.