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

  2. alpha

  3. alpha beta

  4. Compilation fails

  5. No output is produced

  6. An exception is thrown at runtime

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

The code contains compilation errors. In the first if, b3 appears twice without proper grouping for the AND operator precedence. More critically, the second if references b1, which is never declared. These undefined variables prevent compilation.

Multiple choice technology programming languages
  1. 9 foo47 86foo

  2. 9 foo47 4244foo

  3. 9 foo425 86foo

  4. 9 foo425 4244foo

  5. 72 foo47 86foo

  6. 72 foo425 86foo

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

String concatenation is left‑to‑right. The first print yields a space, then 7 and 2 become "72" surrounded by spaces. The second print concatenates "foo", 42 and 5 giving "foo425" plus a trailing space. The final println adds 42+44=86 to "foo" producing "86foo". Hence the output matches "72 foo425 86foo".

Multiple choice technology programming languages
  1. QCMPRES: %eval(&x + &y) CMPRES: 15

  2. CMPRES: 15 QCMPRES: %eval(&x + &y)

  3. QCMPRES: 15 CMPRES: 15

  4. QCMPRES:%eval(&x+&y) CMPRES: 15

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

The %NRSTR function masks its argument at compilation, so &a is assigned the literal text '%eval(&x + &y)' without resolution. %QCMPRES quotes the masked text and removes extra blanks, returning the masked form as-is. %CMPRES attempts to resolve the reference; since &a contains masked text, it resolves to '%eval(&x + &y)' and evaluates to 15. Therefore QCMPRES shows the masked literal, while CMPRES shows the computed value.

Multiple choice technology programming languages
  1. false<new line>false<new line>false<new line>dar

  2. false<new line>true<new line>false<new line>Poddar

  3. Compiler Error

  4. true<new line>true<new line>FALSE<new line>dar

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

StringBuffer does not override equals(), so both == and .equals() perform reference comparison. sb1 and sb2 are different objects (different content - one has trailing space), so all comparisons return false. substring(3) on 'Poddar' returns characters from index 3: 'd','a','r' = 'dar'.

Multiple choice technology programming languages
  1. OF(11) is: 45

  2. OF(11) is: 56

  3. OF(11) is: 89

  4. OF(11) is: 111

  5. Compilation fails

  6. An exception is thrown at runtime.

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

The code has a syntax error on the line 'else (x <= 4) {'. The 'else' statement cannot have a condition in parentheses - that syntax is for 'else if'. When you want a condition, you must use 'else if' not just 'else'. This causes compilation to fail, making option E correct.

Multiple choice technology programming languages
  1. -

  2. -c

  3. -c2

  4. -2c

  5. -c22b

  6. -2c2b

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

To solve this question, we need to trace the execution of the code and see how the value of the variable s changes.

Starting with the main method, it creates a new instance of the Plane class and calls its method s1().

In the s1() method, it calls the method sl().

In the sl() method, it calls the method s2(). Since s2() throws an exception, execution of the sl() method is transferred to the catch block. Here, it appends "c" to the value of s.

Control is then transferred back to the s1() method, which then returns to the main method. Finally, the value of s is printed to the console, which is "-c" since the catch block was executed.

Therefore, the answer is: B. -c

Multiple choice technology programming languages
  1. 8

  2. 8 7

  3. 8 7 6

  4. Compilation fails

  5. An exception is thrown at runtime

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

The provided Java snippet contains several syntax errors: mismatched braces, missing parentheses, and inconsistent variable names (X vs x). These prevent successful compilation, making Compilation fails the correct answer; the code never runs, so runtime or output options are invalid.

Multiple choice technology programming languages
  1. abc

  2. abcde

  3. Compilation fails due only to an error on line 7.

  4. Compilation fails due only to an error on line 8.

  5. Compilation fails due only to an error on line 10.

  6. Compilation fails due only to an error on line 11.

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

The code has multiple errors. Line 7 has 'xl' (lowercase L) instead of 'x1', which would cause a compilation error. However, the more critical error for this question is on line 11: 'case x4' attempts to use a variable (x4) in a switch case statement. In Java, switch case expressions must be constant expressions (compile-time constants). While x4 is declared final, it's of type Integer (wrapper class), not int, so it's not a compile-time constant. Cases can only use: constant int values, final int primitives initialized with literals, or enum constants. Integer wrapper objects are never compile-time constants.

Multiple choice technology programming languages
  1. An exception is thrown at runtime.

  2. "String is empty" is printed to output

  3. Compilation fails

  4. "String is not empty" is printed to output.

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

The code uses the bitwise OR operator | instead of the logical OR operator ||. With |, both sides are always evaluated. When str is null, str.length() is still called, causing a NullPointerException at runtime. The fix is to use || which short-circuits: if str == null is true, str.length() is never evaluated.

Multiple choice technology programming languages
  1. Compilation fails.

  2. An exception is thrown at runtime.

  3. The code executes normally and prints "sleep".

  4. The code executes normally, but nothing is print ed.

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

The code compiles and runs successfully. Thread.sleep(3000) is a static method that pauses execution for 3 seconds. The InterruptedException is properly declared in the throws clause, satisfying the compiler. After sleeping, 'sleep' is printed to console. This is standard usage - no compilation errors or runtime exceptions occur.

Multiple choice technology operating systems
  1. "Hello" will be printed 3 times

  2. "Hello" will be printed 4 times

  3. "Hello" will be printed 8 times

  4. Error

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

Each fork() call creates a new process, doubling the number of processes. After 3 fork() calls: 1 → 2 → 4 → 8 processes. All 8 processes execute the printf statement, so 'Hello' prints 8 times. This is a classic process creation demonstration in UNIX systems.

Multiple choice technology
  1. parseFloat()

  2. toFloat()

  3. float()

  4. stringToFloat()

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

parseFloat() is the standard JavaScript/ActionScript function that parses a string and converts it to a floating-point number. It extracts the first valid number from the beginning of the string. The other options (toFloat, float, stringToFloat) are not standard functions in JavaScript or ActionScript.

Multiple choice technology programming languages
  1. 234

  2. 334

  3. 2334

  4. 0123456

  5. 01234456

  6. 12334567

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

The regex \d* matches zero or more digits, finding matches at positions 0, 1, 2, 3, 4, 5, 6. The output format shows position+group, giving: 0 + '' (empty match at start), 1 + '' (between a and b), 2 + '' (between b and 3), 3 + 3, 4 + '' (between 3 and 4), 5 + 4, 6 + '' (between 4 and e). This produces 01234456. Option E is correct.

Multiple choice technology programming languages
  1. 8/9/05 5:54 PM

  2. 1123631685981L

  3. An exception is thrown at runtime.

  4. Compilation fails due to a single error in the code.

  5. Compilation fails due to multiple errors in the code.

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

DateFormat is an abstract class and cannot be instantiated directly. You must use concrete subclasses like SimpleDateFormat. The code attempts to create a new DateFormat() on line 5, which will cause a compilation error. Option E is correct - there are multiple compilation errors because DateFormat is abstract and cannot be instantiated.