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
  1. function of Parent

  2. function of Child

  3. function of Child function of Parent

  4. function of Child function of Parent

  5. Error in the program

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

Given program involves method overriding. Method Overriding: Using this feature, sub-class or child class can provide specific implementation of the method that is already provided by the parent class. In this program, func() is the method overriden by the child class as parent class already contains same method with same siganture fun().

Hence child class func() method overrides parent class func() method which prints message inside func() of child class only but not parent class. This option is true.

Multiple choice
  1. 81

  2. 45

  3. 25

  4. Error in the program

  5. None of the above

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

  Concept involved here in the program is function overloading. func is the signature common of the method which is present in both Test (parent class) & Hello (base class). But both vary in number of parameter which distinguishes them.

obj.func(5) which calls func(int x) hence output will be computed as follows: a*x=9*5=45 This option is true.

Multiple choice
  1. 60

  2. 66

  3. 50

  4. 55

  5. Compile time error

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

 This program describes about abstract class. virtual int func()=0;     is a pure virtual function hence Test class becomes abstract class. Implementation of func() is present in Imp class where we are inheriting the abstract class Test into Imp class. int x=++a*b++; Initially a=10,b=5; ++a is pre-increment which makes value of 'a' as 11 & b++ is post-increment , until completion the statement execution 'b' value is 5. Only after completing the execution of the statement the value of 'b' is incremented. Hence 11*5=55: This option is correct.

Multiple choice
  1. Prints 3020

  2. Prints 3010

  3. Will result in run time error

  4. Prints 3030

  5. None of the above

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

First 'i' will be printed as 30, as preference is given to local variable. In front of second 'i', ::(scope resolution) operator is given. :: means to manipulate a global variable, in case a local variable also has the same name.

Multiple choice
  1. Both a and b

  2. Both c and d

  3. Only a

  4. All codes

  5. None of the above

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

>> is bitwise right shift operator.a)(32)10=(100000)2. After >>2 we get, (8)10=(001000)2b) (16)10=(010000)2. After >>1 we get, (8)10=(001000)2. This option is correct as we are getting ‘8’ after right shift by 2.

Multiple choice
  1. 1 0 01 1 01 1 1

  2. 0 0 10 1 01 0 0

  3. 1 0 00 1 00 0 1

  4. 0 0 00 0 00 0 0

  5. None of the above

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

If we trace the program as follows: j=0 j=1 j=2k=0 k=0 k=0k==j k.

Multiple choice
  1. base d base s derived d derived s

  2. base d base s base d base s

  3. base d base s base d derived s

  4. none of the above

  5. all a, b and c

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

The show() function is defined as virtual while display() function is not defined as virtual. When function is made virtual, C++ determines which function to use at run time based on the type of object pointed by the base class.

Multiple choice
  1. answer = 49

  2. answer = 36

  3. answer = 64

  4. error in the program

  5. none of these

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

Program will first increment the value and then find the square of incremented value. So, answer will be 7 ++ = 8 * 8 = 64 Hence, option (3) is correct.  

Multiple choice
  1. 0 1 4 9 16 25

  2. 0 1 1 2 3

  3. 0 1 1 2 3 5

  4. Error in program

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

Program will just print Fibonacci numbers as the sum of previous digits in counting up to 5, i.e. 0 1 1 2 3 5. So, option (3) is correct.

Multiple choice
  1. 22.355555

  2. 28.055555

  3. 28.655555

  4. 22.655555

  5. 28.355555

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

The program will evaluate the series as X + X2 / 2! + X4 / 4! + X6 / 6! + .................... Xn / n! So, putting values of x and y in program, the result will be 28.355555. Hence, option (5) is correct.

Multiple choice
  1. answer = 9

  2. answer = 16

  3. answer = 25

  4. garbage value

  5. none of these

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

The value is returned by input 5. It is subtracted as 1 - 5 + 1 = 2 – 5 = (- 3)2 = 9; Pow(3,2) = 32 = 9 Hence, option (1) is correct.

Multiple choice
  1. k = 0, l = 2, a = 0.00000, b = 2.00000

  2. ERROR:-cannot convert an integer to float

  3. k = 0, l = 2, a = garbage value, b = garbage value

  4. k = 0, l = 2, a = 0, b = 2

  5. None of these

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

 Output will be k = 0, l = 2, a = 0.0000 and b = 2.0000 Hence, option 1 correct.

Multiple choice
  1. P = - 2.54768

  2. P = - 2.45748

  3. P = - 2.54678

  4. P = - 2.54878

  5. P = - 2.45768

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

This option is correct. First z / k will be solved which comes out to be 1.59649. Then a / b will be solved which comes out to be 1.25397. Then u % t will be solved which comes out to be 4. So, the last expression will be: 5.1 + 1.59649 - 1.25397 - 11.9 + 4. Solving it, the result will be -2.45748.

Multiple choice
  1. 9

  2. 10

  3. 11

  4. 12

  5. None of these

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

This program will run until d becomes greater than 9. As we can see the value of c (c=1) is greater than d (d=0). So c will always be one greater than the value of d, because both are incrementing at the same time. So, when d = 0 (d <= 9), condition becomes true. So when d becomes 1, c becomes 2, and when d is 9 (d <= 9), which is again true, then d becomes 10 and c becomes 11, which is one greater than d. The program runs 10 times. So final value of c is 11.