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. 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. Buffer overflow

  2. Off by one error

  3. Format string vulnerability

  4. No vulnerabilities are present in this code

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

The code has a format string vulnerability because sprintf() uses the 'data' array as the format string. If data contains format specifiers like %200d, they will be interpreted as format directives rather than literal text, potentially leaking stack data or causing crashes. Buffer overflow is not the primary issue.

Multiple choice technology security
  1. Buffer overflow

  2. Off by one error

  3. Format string vulnerability

  4. No vulnerabilities are present in this code

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

The code has a format string vulnerability because printf() directly uses argv[1] as the format string. If argv[1] contains format specifiers like %n or %s, they will be interpreted by printf, allowing potential code execution or information disclosure. This is not a buffer overflow.

Multiple choice technology security
  1. Heap overflow

  2. Integer overflow

  3. Off by one error

  4. None

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

The loop 'do { i++; k[i]=ch+i; } while(i<3);' will execute for i=1, 2, and 3. Since 'k' is defined as 'char k[3]', the valid indices are 0, 1, and 2. Writing to 'k[3]' causes an off-by-one error (buffer overflow).

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

  2. Arc Injection

  3. Buffer Overflow

  4. Arc Injection AND Buffer Overflow

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

The code has multiple vulnerabilities: (1) Buffer overflow - strcpy() without bounds checking on buffer1 and buffer2 can overflow the 5-byte buffers. (2) Arc injection - FILE *file[2] creates an array of 2 FILE pointers but the code attempts to use file[x] where x can be manipulated. (3) The second strcpy uses buffer1 instead of buffer2 - this is a bug that copies argv[1] into buffer1 twice. Option D correctly identifies both arc injection and buffer overflow.