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. a. the code will compile an print "Equal".

  2. b. the code will compile an print "Not Equal".

  3. c. the code will cause a compiler error

  4. d.

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

The trim() method creates a new String object in memory even if the resulting trimmed content is identical to an existing literal. Using the == operator compares object references rather than content, so comparing a newly allocated trimmed string to a literal string pool reference evaluates to false.

Multiple choice technology programming languages
  1. test

  2. Exception

  3. Compilation fails.

  4. NullPointerException

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

Java requires catching more specific exceptions before general ones. NullPointerException is a subclass of Exception, so the catch block for NullPointerException (line 18) is unreachable - any NullPointerException would be caught by the broader Exception catch at line 16 first. This violates Java's exception handling rules and causes compilation failure.

Multiple choice technology programming languages
  1. B

  2. The code runs with no output.

  3. An exception is thrown at runtime.

  4. Compilation fails because of an error in line 15.

  5. Compilation fails because of an error in line 18.

  6. Compilation fails because of an error in line 19.

Reveal answer Fill a bubble to check yourself
F Correct answer
Multiple choice technology programming languages
  1. java test

  2. java -ea test

  3. java test file1

  4. java -ea test file1

  5. java -ea test file1 file2

  6. java -ea:test test file1

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

Assertions are disabled by default in Java. The -ea flag enables assertions. The assertion checks if a.length == 1, so it fails when the args array has 0 or 2+ elements. Option B (java -ea test) has 0 args, triggering the assertion. Option E (java -ea test file1 file2) has 2 args, also triggering it. Options without -ea don't trigger assertions regardless of arg count.

Multiple choice technology programming languages
  1. 3,2, 1,

  2. 1, 2, 3,

  3. Compilation fails.

  4. The code runs with no output.

  5. An exception is thrown at runtime.

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

The code has a compilation error. In the for-each loop at line 18, reverse(list) is called, which returns Iterator. However, the for-each syntax expects either an array or an Iterable (Collection), not an Iterator directly. You cannot use a for-each loop with an Iterator - you must use hasNext()/next() instead. This is a syntax error that prevents compilation.

Multiple choice technology programming languages
  1. null

  2. zero

  3. some

  4. Compilation fails.

  5. An exception is thrown at runtime.

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

The code fails to compile because of a syntax error in the 'else' block. In Java, an 'else' statement cannot have a condition. It should be 'else if (str.length() == 0)'. Additionally, the string literal uses a mismatched quote ('null’).

Multiple choice technology programming languages
  1. snootchy 420 third second first

  2. snootchy 420 first second third

  3. first second third snootchy 420

  4. third second first siiootchy 420

  5. third first second snootchy 420

  6. first second first third snootchy 420

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

The constructors are called in sequence: Bootchy() calls this("snootchy"), which calls this(420, "snootchy"). The third constructor finishes first, then the second, then the first. Thus, 'third second first' is printed, followed by the values.

Multiple choice technology security
  1. Program works when there is only 1 argument with program

  2. Program works when there are 3 arguments with program

  3. Program works when there are 4 arguments with program

  4. Program never executes successfully

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

In the loop, delete ptr executes on first iteration (k!=0). On subsequent iterations, *ptr=k uses already-freed memory, use-after-free crash. The loop also assumes argv has 4+ elements without checking. Program will crash or have undefined behavior.

Multiple choice technology security
  1. A run-time error is encountered and the program aborts

  2. unsigned int variables cannot store the sign (+ or -) of the number. The sign is discarded and only the number is stored in i

  3. A large positive number will be stored in i

  4. Unsigned int variables cannot store signed numbers. Hence in this program i will contain garbage values.

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

In C, when a negative integer is read into an 'unsigned int' using '%u', the bit pattern of the negative number (in two's complement) is interpreted as a positive value. This results in a very large positive number.

Multiple choice technology security
  1. 1289945278

  2. garbage. Integer j cannot hold such large values

  3. 9879879870

  4. Program is aborted

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

i=987987987 (0x3ADE9DE3). i*10=9879879870, which exceeds 32-bit signed int range. Wraparound: 9879879870 mod 2^32 = 1289945278 (0x4CE9641E). This is integer overflow; result is truncated, not garbage or abort. The value wraps modulo 2^32.

Multiple choice technology security
  1. value of tree

  2. value of node

  3. value of i

  4. garbage-- its a dangling pointer

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

The function myfunc() returns a pointer to either 'tree' or 'i', both of which are local variables to that function. When myfunc() returns, those local variables go out of scope and their memory is freed. The pointer stored in 'leaf' becomes a dangling pointer pointing to garbage memory. Dereferencing *leaf in main() accesses invalid memory. Option D is correct - it's a dangling pointer containing garbage.

Multiple choice java
  1. Prints: t i g

  2. Prints: S r n

  3. Compilation error at lines 1, 2 and 3.

  4. Compilation error at lines 4, 5 and 6.

  5. The code compiles and runs fine.

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

The code uses reserved words as variable names (String, Question59, main) which is legal in Java. The loop iterates: main=0 prints 'S', main=2 prints 'r', main=4 prints 'n', main=6 exceeds 2 and breaks. Output: 'S r n'. The break statement syntax is incorrect (should be 'break;' not 'break Object;'), but since the break executes before the labeled syntax error is reached, the code runs. Option E states the code compiles and runs, which is true despite the unreachable labeled break.

Multiple choice technology programming languages
  1. The above code will not compile, Vector v is not initialized.

  2. The above code will compile and throw a Runtime Exception

  3. The above code will compile and not throw any Exception during runtime. V is initialized to null

  4. None of the Above.

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

Final instance variables must be initialized exactly once - either at declaration, in an instance initializer block, or in every constructor. The code declares 'final Vector v' but the constructor doesn't initialize it, causing a compile-time error.

Multiple choice technology programming languages
  1. The code will compile and print "Welcome"

  2. The code will compile and print "Good Bye"

  3. The code will cause a compiler error

  4. None of the Above

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

The trim() method returns a new String object, not the same literal reference. Since ' String '.trim() creates a new String object and 'String' is a literal, they are different objects with the same content. Using == compares references, not content, so the comparison is false, printing 'Good Bye'.

Multiple choice technology programming languages
  1. 0

  2. 1

  3. 2

  4. Compilation Error

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

The loop runs twice. In the first iteration, x becomes 1 (via ++x) and y becomes 1. In the second iteration, x becomes 2 and y becomes 0. The loop terminates, and 2 is printed.