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 b

  2. b c

  3. a b c

  4. Compilation fails

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

Command-line arguments: args[0]=a, args[1]=b, args[2]=c. The loop starts at x=1, so it prints args[1]=b and args[2]=c with spaces. Index 0 (a) is skipped. Output is b c.

Multiple choice technology programming languages
  1. null

  2. zero

  3. some

  4. Compilation fails

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

The code has syntax error: else if (str.length() == 0) is missing the if keyword. It should be else if (str.length() == 0) not else (str.length() == 0). This causes compilation failure.

Multiple choice technology programming languages
  1. TRUE

  2. FALSE

  3. Compilation Error

  4. Run-time Error

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

The code uses assignment (=) instead of equality (==). In Java, var = true assigns true to var and returns true, so the condition is true and 'TRUE' is printed. This is a common mistake that compiles and runs but produces unexpected behavior.

Multiple choice technology web technology
  1. x = 4, y = 1, z = 5

  2. x = -7, y = 1, z = 5

  3. x = 4, y = 2, z = 6

  4. x = 3, y = 2, z = 6

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

The prefix increment ++y makes y equal 2 immediately. The expression evaluates to 0 - 2 + z++ which is -2 + 5 = 3. Post-increment z++ increases z to 6 after evaluation. Thus, x becomes 3, y becomes 2, and z becomes 6.

Multiple choice technology programming languages
  1. printf("%d\n",p);

  2. printf("%u\n",p);

  3. printf("%lu",p);

  4. printf("%p\n",(void*)p);

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

The %p format specifier is the portable, standard way to print pointer values in C. It requires a void* argument, so (void*) cast ensures proper conversion. Options A, B, and C use incorrect format specifiers - %d expects int, %u expects unsigned int, and %lu expects unsigned long, none of which are guaranteed to correctly represent a pointer on all platforms.

Multiple choice technology programming languages
  1. Failure

  2. success

  3. Exception will be thrown

  4. Compilation error

  5. Neither

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

The ternary operator has left-associativity. The expression str=(b)?"success": (x=0)?"Failure":"Neither" is parsed as str = ((b)?"success": (x=0))?"Failure":"Neither". Since b is true, the first ternary returns "success". Then it tries to evaluate ("success")?"Failure":"Neither", which attempts to use a String as a boolean condition - this is a compilation error because you cannot use a String as a boolean expression in Java.

Multiple choice technology programming languages
  1. 155

  2. Compilation error

  3. Exception

  4. 20

  5. 5 5

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

The code fails to compile because the variable 'tr' is undefined (it should be 'tp'), and the main method attempts to access a private field 'i' of class Top directly, which is forbidden in Java.

Multiple choice technology programming languages
  1. 2

  2. 4

  3. Exception

  4. Compilation error

  5. 9

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

The array a has a[1] = {9,2} which is an int array of length 2 (indices 0 and 1). When we try to access b[2] where b = a[1], we're accessing index 2 in an array that only has indices 0 and 1. This causes an ArrayIndexOutOfBoundsException at runtime, not a compilation error (the array sizes are determined at runtime for jagged arrays).

Multiple choice technology programming languages
  1. TRUE

  2. true

  3. FALSE

  4. Compilation Error

  5. Run time Error

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

The code uses assignment (=) not comparison (==). The statement if(var = true) assigns true to var, then evaluates the condition as true, so 'TRUE' is printed. This is a common bug where assignment is mistaken for equality check.