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

  2. 10

  3. 101

  4. 1101

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

Even though o and oc are reference variables of different types, they are both referring to the same object. This means that == will resolve to true and that the defaultequals() method will also resolve to true.

Multiple choice
  1. 1 and 3

  2. 2 and 4

  3. 3 and 4

  4. 1 and 2

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

In Java, String.equals() compares content. When o = s, o references the same String object. o.equals(s) returns true because String's equals() compares character sequences. s.equals(o) also returns true - Object equals() is virtual and String overrides it to compare content. Output is A and C.

Multiple choice
  1. x2.equals(x1)

  2. x3.hashCode() == x4.hashCode()

  3. x5.hashCode() != x6.hashCode()

  4. x8.equals(x7)

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

By contract, if two objects are equivalent according to the equals() method, then thehashCode() method must evaluate them to be . Option A is incorrect because if the hashCode() values are not equal, the two objects must not be equal. Option C is incorrect because if equals() is not true there is no guarantee of any result from hashCode(). Option D is incorrect because hashCode() will often return  even if the two objects do not evaluate to equals() being true.

Multiple choice
  1. There is a syntax error on line 1.

  2. There are syntax errors on lines 1 and 6.

  3. There are syntax errors on lines 1, 6, and 8.

  4. There is a syntax error on line 6.

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

Using the integer 1 in the while statement, or any other looping or conditional construct for that matter, will result in a compiler error. This is old C Program syntax, not valid Java. A, B and C are incorrect because line 1 is valid (Java is case sensitive so While is a valid class name). Line 8 is also valid because an equation may be placed in a String operation as shown.

Multiple choice
  1. Line 11

  2. Line 12

  3. Line 14

  4. Line 22

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

Assert statements should not cause side effects. Line 22 changes the value of z if the assert statement is false. Option A is fine; a second expression in an assert statement is not required. Option B is fine because it is perfectly acceptable to call a method with the second expression of an assert statement. Option C is fine because it is proper to call an assert statement conditionally.

Multiple choice
  1. 1

  2. 2

  3. 3

  4. 4

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

The program flows as follows: I will be incremented after the while loop is entered, then I will be incremented (by zero) when the for loop is entered. The if statement evaluates to false, and the continue statement is never reached. The break statement tells the JVM to break out of the outer loop, at which point I is printed and the fragment is done.

Multiple choice
  1. 5 2

  2. 5 3

  3. 6 3

  4. 6 4

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

In the first two iterations x is incremented once and y is not because of the short circuit&& operator. In the third and forth iterations x and y are each incremented, and in the fifth iteration x is doubly incremented and y is incremented.

Multiple choice
  1. 9

  2. 9.9

  3. 9.0

  4. Error in the program

  5. None of the above

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

 typedef creates a new name for a given datatype.

typedef int hello;     //hello is the new name of integer datatype.

hello i=9.9; cout<<i;

Which displays value of 'i'. As 'i' is of integer datatype because is declared as hello type which is the name given to integer datatype using typedef. Hence, prints 9.

 

Multiple choice
  1. 1_7

  2. 7_1

  3. 5_1

  4. 6_2

  5. None of the above

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

 Though variables x,y are intialized with 6, 8 respectively. Due to below statement the values of x,y are changed. (x=5)&&(x=7) ? y=1:y=2; Conditional operator (?:) follows right to left associativity. && operator follows left to right associativity. = opeartor always returns true. Evaluate the condition (x=5)&&(x=7) first. proceed left to right due to && Hence x=7 finally, and condition returns true because (true&&true implies true) Hence y=1; Which prints 7_1

Multiple choice
  1. 12345 12345 12345 12345 12345

  2. 12345 1234 123 12 1

  3. 1 12 123 1234 12345

  4. Error in the program

  5. None of the above

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

Lets trace out i,j,k values of the given program:|k|i|j| |---|---|---| |5|1|1 2 3 4 5| |4|2|1 2 3 4| |3|3|1 2 3| |2|4|1 2| |1|5|1|

As we are displaying 'j' values, hence the output will be the similar to column 'j' as shown in the given table. In the table each row represents a single iteration of first for loop. We are decrementing value of 'k' and incrementing 'i'. More over second for loop iteration depends on value of 'k' which is decreasing through out the program hence we can see it narrows down in the output. This option is correct.

Multiple choice
  1. constructor of Test constructor of Test destructor of Test destructor of Test

  2. constructor of Test destructor of Test constructor of Test destructor of Test

  3. constructor of Test constructor of Test

  4. constructor of Test destructor of Test

  5. None of the above

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

 Given class Test contains a default constructor & default destructor. We know constructor is called when we create instance for a class. Destructor is called when the instance variable doesnt point to any object or simply when it gets dereferenced. Test a;  //prints constructor of Test Test b;  //prints constructor of Test Now after end of the program, created instances are de-referenced. Hence prints destructor of Test (for instance 'a') prints destructor of Test (for instance 'b')