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 web technology
  1. prints false

  2. prints true

  3. Complier error

  4. None of the above

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

According to the IEEE 754 standard for floating-point arithmetic, which Java adheres to, positive zero and negative zero are mathematically and logically considered equal. Therefore, the comparison 0.0 == -0.0 evaluates to true, and the program prints "true" rather than false.

Multiple choice technology web technology
  1. will Print Equal

  2. will Print Not Equal

  3. compile time error

  4. none of the above

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

The replace method creates and returns a new String object because a modification occurred. The == operator compares object references rather than their actual text content. Since two distinct string objects are created in memory, the reference comparison evaluates to false, resulting in "Not Equal" being printed.

Multiple choice technology programming languages
  1. an IntegerArithmeticException

  2. an ArithmeticException

  3. a DivideByZeroException

  4. a NumberFormatException

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

Java throws an ArithmeticException when an exceptional arithmetic condition has occurred, such as integer division by zero. Other options like IntegerArithmeticException and DivideByZeroException do not exist in the standard Java library, while NumberFormatException is thrown when attempting to convert an invalid string to a numeric type.

Multiple choice technology programming languages
  1. To add numbers together

  2. To keep track of data in the memory of the computer

  3. To print words on the screen

  4. To write Java

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

Variables exist to store data in memory, allowing programs to keep and manipulate values. The other choices describe specific operations (adding, printing, writing code) that are not the fundamental purpose of variables.

Multiple choice technology programming languages
  1. null

  2. life

  3. universe

  4. everything

  5. Compilation fails

  6. An exception is thrown at runtime

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

The nested ternary first checks i<40 (false), then i>50 (false), so the final else clause is chosen. Hence s is assigned "everything". All other options are incorrect because the conditions do not match the value 42.

Multiple choice technology programming languages
  1. test case

  2. production

  3. test case live2

  4. Compilation fails

  5. An exception is thrown at runtime

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

The bitwise OR operator | evaluates both operands, so when args.length==1, Java still attempts args[1].equals("test"), causing ArrayIndexOutOfBoundsException. Logical OR || would short-circuit and avoid this. Only one argument "live2" was passed.

Multiple choice technology programming languages
  1. 5 1

  2. 5 2

  3. 5 3

  4. 8 1

  5. 8 2

  6. 8 3

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

Assuming the intended variable is x++, the loop runs five times. ++x and ++y increment before comparison; the first two iterations increment both without triggering the body. From the third iteration onward, ++x exceeds 2, short‑circuiting the || and preventing ++y, then x is incremented again. Final values are x=8, y=2, yielding "8 2".

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.