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 security
  1. value of tree

  2. value of node

  3. value of i

  4. garbage-- its a dangling pointer

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

The function myfunc() returns a pointer to either 'tree' or 'i', both of which are local variables to that function. When myfunc() returns, those local variables go out of scope and their memory is freed. The pointer stored in 'leaf' becomes a dangling pointer pointing to garbage memory. Dereferencing *leaf in main() accesses invalid memory. Option D is correct - it's a dangling pointer containing garbage.

Multiple choice technology security
  1. Buffer Overflow

  2. Command Injection

  3. CSRF

  4. XSS

  5. XST

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

The Java code uses Runtime.exec() to execute 'cmd.exe /C' without proper input validation. If user input were concatenated into this command string, an attacker could inject arbitrary system commands after the /C flag. This is a classic Command Injection vulnerability where the application passes unsanitized data directly to a system shell. Buffer Overflow (A) would require memory corruption, CSRF (C) requires cross-site request forgery context, XSS (D) needs web page output rendering, and XST (E) relates to cross-site tracing.

Multiple choice java
  1. Prints: t i g

  2. Prints: S r n

  3. Compilation error at lines 1, 2 and 3.

  4. Compilation error at lines 4, 5 and 6.

  5. The code compiles and runs fine.

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

The code uses reserved words as variable names (String, Question59, main) which is legal in Java. The loop iterates: main=0 prints 'S', main=2 prints 'r', main=4 prints 'n', main=6 exceeds 2 and breaks. Output: 'S r n'. The break statement syntax is incorrect (should be 'break;' not 'break Object;'), but since the break executes before the labeled syntax error is reached, the code runs. Option E states the code compiles and runs, which is true despite the unreachable labeled break.

Multiple choice technology programming languages
  1. The above code will not compile, Vector v is not initialized.

  2. The above code will compile and throw a Runtime Exception

  3. The above code will compile and not throw any Exception during runtime. V is initialized to null

  4. None of the Above.

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

Final instance variables must be initialized exactly once - either at declaration, in an instance initializer block, or in every constructor. The code declares 'final Vector v' but the constructor doesn't initialize it, causing a compile-time error.

Multiple choice technology programming languages
  1. Float.POSITIVE_INFINITY

  2. Double.POSITIVE_INFINITY

  3. runtime Exception

  4. None of the Above

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

Math.max is overloaded for double and float. When comparing a float and a double, the float is promoted to a double. The result of Math.max(double, double) is a double, returning Double.POSITIVE_INFINITY.

Multiple choice technology programming languages
  1. The code will compile and print "Welcome"

  2. The code will compile and print "Good Bye"

  3. The code will cause a compiler error

  4. None of the Above

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

The trim() method returns a new String object, not the same literal reference. Since ' String '.trim() creates a new String object and 'String' is a literal, they are different objects with the same content. Using == compares references, not content, so the comparison is false, printing 'Good Bye'.

Multiple choice technology programming languages
  1. 0

  2. 1

  3. 2

  4. Compilation Error

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

The loop runs twice. In the first iteration, x becomes 1 (via ++x) and y becomes 1. In the second iteration, x becomes 2 and y becomes 0. The loop terminates, and 2 is printed.

Multiple choice technology programming languages
  1. 2

  2. 3

  3. 1 2

  4. 2 3

  5. 1 2 3

  6. Compilation fails.

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

The first condition (x==4) && !b2 is false because x=5, so '1' is not printed. Print('2') always executes, printing '2'. The second condition (b2 = true) assigns true to b2, then evaluates (true && b1) which is true, so '3' is printed. Output: '2 3'.

Multiple choice technology programming languages
  1. 5

  2. 10

  3. 12

  4. 17

  5. 24

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

The output from line 5 of the Test class would be 10.

Explanation:

In the Test class, there is an instance variable x with a value of 12.

The method takes a parameter x and performs an addition operation x += x, which is equivalent to x = x + x.

When the method is called with an argument of 5 (t.method(5)), the local variable x inside the method is set to 5.

The addition operation x += x is then performed, resulting in x being updated to 10.

Finally, System.out.println(x) prints the value of x, which is 10.

Therefore, the output from line 5 of the Test class would be 10, so the correct answer is C.

Multiple choice technology programming languages
  1. harrier

  2. shepherd

  3. retriever

  4. Compilation fails.

  5. retriever harrier

  6. An exception is thrown at runtime.

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

The switch statement contains a critical syntax error on line 18: 'case default:' is invalid. In Java switch statements, 'default' is a keyword that stands alone and cannot be combined with 'case'. The correct syntax is simply 'default:' without the word 'case' preceding it. This causes compilation to fail regardless of the enum value being tested.

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

Line 15 has a syntax error: 'else (str.length() == 0)' is missing the keyword 'if'. In Java, 'else' must be followed immediately by a statement or block, or by 'if' for an else-if clause. The parentheses alone make no sense syntactically. This causes compilation failure regardless of the string value being tested.

Multiple choice technology programming languages
  1. r, t, t,

  2. r, e, o,

  3. Compilation fails.

  4. An exception is thrown at runtime.

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

Line 13 attempts to assign an integer (str.length() returns int) to a boolean variable (check is int, but if condition requires boolean). In Java, check = str.length() is an assignment, not a comparison, and the types are incompatible for the if condition.

Multiple choice technology programming languages
  1. r, t, t,

  2. r, e, o,

  3. Compilation fails.

  4. An exception is thrown at runtime.

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

Line 13 attempts to assign an integer (str.length() returns int) to a boolean variable (check is int, but if condition requires boolean). In Java, check = str.length() is an assignment, not a comparison, and the types are incompatible for the if condition.

Multiple choice technology programming languages
  1. prints "Clove is nice"

  2. prints "Mint is ok"

  3. prints "Sage is average"

  4. Class cast Exception at runtime.

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

The variable c is declared as type Mint. The method c.quality(h) calls quality() on a Mint reference. The argument h is declared as Clove, so the method signature quality(Mint c) in class Mint doesn't match. JVM looks for quality(Clove) in Mint's hierarchy, finds it in Clove class (parent), and executes that due to method resolution rules.