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

  2. 3

  3. 4

  4. 8

  5. 9

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

The regex \d+ matches one or more digits. In 'ab2c4d67', find() locates three matches: '2' (position 2), '4' (position 4), and '67' (position 6-7). The count variable starts at 0, and the while loop increments it for each match, resulting in count=3. Option D (8) would count individual digit characters, while option C (4) might expect '6' and '7' separately.

Multiple choice technology programming languages
  1. 1 2

  2. 1 2 3 45 6

  3. 1 2 3 4 5 6

  4. 1 2 a 3 45 6

  5. 1 2 followed by an exception

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

The Scanner processes tokens '1', '2', and then encounters 'a'. When sc.nextInt() is called to parse 'a' as an integer, it throws an InputMismatchException. Consequently, '1 2' is printed before the program terminates with an exception.

Multiple choice technology programming languages
  1. Data Hiding

  2. Data Shadowing

  3. Data Obscuring

  4. None of the Above

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

When a local variable within a block or method has the same name as a member variable in the surrounding class scope, the local variable shadows the class variable. This compiler concept is known as variable or data shadowing.

Multiple choice technology programming languages
  1. true false true false true

  2. true false false true true

  3. true false false false true

  4. true false true false false

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

String literals (s1, s2) reference the same string pool object. new String() creates distinct heap objects (s3, s4). The == operator compares references, not content. intern() returns the string pool reference, so comparisons involving intern() yield true when the content is in the pool.

Multiple choice technology testing
  1. 10 10 10

  2. 10 10 20

  3. Runtime Exception

  4. Compilation error

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

Interface variables are implicitly final and static, so they cannot be modified. The line x=x+10 attempts to reassign a final variable, causing a compilation error. The code would print 10 10 before failing on the assignment.

Multiple choice technology security
  1. 1

  2. 2

  3. 1 & 2

  4. No vulnerability

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

In line 1, the loop condition is i <= 3. Since chararray is of size 3 and intarray is of size 3, writing to index 3 (when i == 3) results in an out-of-bounds write (buffer overflow) for both arrays. Hence, line 1 is the source of the loop boundary vulnerability.

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

Inside the loop, ptr is deleted in the first iteration where k != 0. In subsequent iterations, if k != 0 again, the program attempts to dereference and delete the already freed pointer ptr, causing a double-free / undefined behavior. Thus, the program never executes successfully.

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, scanf("%u", &i) expects an unsigned integer representation. If a negative number (e.g. -1) is entered, it is parsed and converted to its unsigned equivalent via two's complement conversion, resulting in a large positive integer being stored in i.

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

In Java, integer multiplication overflows silently according to 32-bit two's complement representation. The math is 987987987 * 10 = 9879879870, which in binary is 0x24CF1D0FE. Truncated to 32 bits, this is 0x4CF1D0FE, which is 1289945278 in decimal.

Multiple choice technology security
  1. XSS

  2. Arc Injection

  3. Buffer Overflow

  4. both 2 and 3

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

strcpy(buffer1, argv[1]) copies without length checking - buffer overflow if argv[1] exceeds 4 bytes (+ null terminator). Arc injection (aka pointer corruption) occurs because the overflow can corrupt the file[] array of FILE pointers stored after the buffers on the stack, redirecting file operations. Both vulnerabilities are present.

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 passes data directly as the format string to sprintf. If data contains format specifiers like %200d, sprintf will interpret them as format directives rather than literal text. Attackers can supply malicious format strings like %n to write arbitrary values to memory, leading to code execution. This is a format string vulnerability, not a buffer overflow.