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

  2. 0

  3. Error:Array value out of bound

  4. Null value

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

Perl arrays are 0-indexed. @array = (1,2,3) has indices 0,1,2. Accessing $array[3] is out of bounds. Unlike many languages, Perl returns undef (undefined value) rather than throwing an error. undef prints as empty string, which appears as null/empty. Option D correctly identifies this as null value.

Multiple choice technology programming languages
  1. 1 2

  2. 4 5

  3. 5 5

  4. Null value 5

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

When assigning an array to a list of scalars, array elements are assigned left-to-right. $scalar1 gets the first element (1), but there are more scalars than elements, so remaining scalars get undef. The print shows 'Null value' (undef rendered as empty) and '5' ($scalar2 never got assigned, defaulting to undef/empty).

Multiple choice technology programming languages
  1. 1 2 Null value

  2. 1 2 0

  3. 1 2 3

  4. Error:Array out of bound

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

In Perl, when a 2-element array is assigned to 3 scalars, the third scalar receives undef (undefined). When printed, undef produces an empty string or an uninitialized value warning. 'Null value' is non-standard Perl terminology but refers to undef.

Multiple choice technology databases
  1. 50

  2. NULL

  3. 5

  4. None of the above

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

The key concept here is how NULL behaves in PL/SQL comparisons. Any comparison with NULL returns NULL (unknown), not true or false. Since variable b is NULL, the expression 'a > b' evaluates to NULL, making the entire AND condition NULL. Because the condition is not true, the IF block doesn't execute, and 'a' remains unchanged at its initial value of 5. Therefore option C (5) is correct.

Multiple choice technology databases
  1. 50

  2. NULL

  3. 5

  4. None of the above

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

The condition a > b (5 > NULL) evaluates to NULL/UNKNOWN because any comparison with NULL returns NULL. In SQL/PLSQL, NULL AND FALSE/TRUE = NULL (falsy). Since the AND condition short-circuits on the NULL result from a > b, the entire condition is false, the IF block doesn't execute, and 'a' remains unchanged at 5.

Multiple choice technology mainframe
  1. 4

  2. 5

  3. 6

  4. 7

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

The PERFORM VARYING loop executes with C starting at 1 and incrementing by 1 until C reaches 6. This means the loop runs when C = 1, 2, 3, 4, 5 (5 iterations total). Each iteration increments RESULT by 1, starting from 0, so the final value is 5. The loop stops before executing when C = 6.

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.