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. This is Test

  2. This is Test Constructor of A

  3. Constructor of A This is Test

  4. Error in the program

  5. None of the above

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

A a;    //creates object for class A, which calls default constructor Hence Constructor of A gets displayed first.a.Test();        //Now we call Test() using class object which prints message inside Test(). i.e This is Test As it matches with output given in this option , Hence true.

Multiple choice
  1. 10

  2. 5

  3. 10 5

  4. Compile time error

  5. None of the above

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

 When we compile the given program it generates compile time error.

Because integer variable 'a' is defined in both Parent classes. Child class inherits both Parent class & child class function func() accesses integer variable 'a' which leads to ambigious situation.

Error generated at linereturn a; Error message : reference to 'a' is ambigious This option is true.

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. Error at line5

  2. Error at line4

  3. Error at line3

  4. 11

  5. Error at line1

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

 This program works fine & there are no compile time errors. Mutable keyword is used to change the values of member variables eventhough the objects are declared as constant. In the program we declared constant object as follows: const Test obj; Now the obj is a constant object where its data members can't be changed. Only if data members are declared with mutable keyword are eligible for manipulation or changes. Hence value is incremented using a++ & output is displayed as 11.

Multiple choice
  1. 200

  2. 209

  3. 189

  4. Compile time error

  5. None of the above

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

 class derived_class:access_specifier base_class We have to understand above syntax inorder to answer this question. when access_specifier is protected: all public & protected members of base_class becomes protected type for derived_class. class Middle:protected Parent  //int a,b are now protected Where Middle() constructor increments value of 'a' * decrements 'b' Hence a=11,b=19 when access_specifier is private: all public & protected of base_class becomes private members for derived_class. So, int a,b are now private for class Child Hence they are accessible to derived_class from the base_class. Which prints a*b=11*19=206

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.