Object Oriented Programming - Functions

6. int a =1 , b=2;

a=chg(b) ;

cout << a << b ;

If the function chg is coded as


int chg(int &x)
{

x = 10;

return ();

}

then   Functions

  • Option : D
  • Explanation : Here the parameter passing mechanism is pass by reference. Any change done to the parameter will be reflected outside the function. So, the value of b, after the exit of the function will be 10.
Cancel reply

Your email address will not be published. Required fields are marked *


Cancel reply

Your email address will not be published. Required fields are marked *


7. int a =1 , b=2;

a=chg(b) ;

cout << a << b ;

If the function chg is coded as


int chg(const int &x)

{

x=10;

return ()

};

then     Functions

  • Option : A
  • Explanation : Here the function chg tries to change the parameter x, which is not allowed as it is declared to be a constant integer. So, the compiler gives an error.
Cancel reply

Your email address will not be published. Required fields are marked *


Cancel reply

Your email address will not be published. Required fields are marked *


8. Which of the following parameter passing mechanism(s) is/are supported by C++, but not by C?

  • Option : B
  • Explanation : As such C does not support pass by reference. But it can be simulated by using pointers.
Cancel reply

Your email address will not be published. Required fields are marked *


Cancel reply

Your email address will not be published. Required fields are marked *


9. If a piece of code can be implemented as a macro or as an inline function, which of the following factors favour implementation as an inline function?

  • Option : D
  • Explanation : Macros do not have an address associated with them as they are processed by the pre-processor.
    They cannot be passed as arguments to a function, etc. Also, macros are replaced in a blind manner without any regard to the context which may result in a stupid code, like
    #define mul(a,b) a*b
    The macro call mul(a, b + 1) will be expanded as a *b+ 1, but our intention was to get a * (b+ 1 ) .
Cancel reply

Your email address will not be published. Required fields are marked *


Cancel reply

Your email address will not be published. Required fields are marked *


10. Assume that the random number generating function - rand( ), returns an integer between 0 and 10000 (both inclusive). If you want to simulate the throwing of a die using this random function, use the expression

  • Option : B
  • Explanation : It should randomly generate any integer between 1 and 6. rand( ) % 6 returns an integer from 0 to 5. To make it 1 to 6, we need to add 1
Cancel reply

Your email address will not be published. Required fields are marked *


Cancel reply

Your email address will not be published. Required fields are marked *


  • Functions Questions can be used to give quizzes by any candidate who is preparing for UGC NET Computer Science
  • This Functions Questions section will help you test your analytical skills in a tricky method, thereby giving you an edge over other students
  • Any student who wants to prepare for DOEACC A Level, DOEACC B Level, and DOEACC C level can also use these Objective Type Questions Answer.
  • All candidates who have to appear for the Kendriya Vidyalaya Entrance exam can also refer to this mcq section.
  • You can also get access to the Functions MCQ ebook.
  • Functions Questions can be used in the preparation of JRF, CSIR, and various other exams.
  • You can also download pdf for these Functions multiple-choice questions Answers.
  • This Functions Multiple Choice Questions Answers section can also be used for the preparation of various competitive exams like UGC NET, GATE, PSU, IES, and many more.
  • Functions Questions can be used to gain a credit score in various undergraduate and postgraduate courses like BSc, MSc and MCA
  • Functions Questions for UGC NET Computer Science

    Functions MCQ

    Functions Multiple choice questions