Exam-GK-MCQ-Questions.Com

Home - Cpp Programming - Functions

Functions Online Exam Quiz

Important questions about Functions. Functions MCQ questions with answers. Functions exam questions and answers for students and interviews.

1. Which of the following statement is correct?

Options

A : Constructors can have default parameters.

B : Constructors cannot have default parameters.

C : Constructors cannot have more than one default parameter.

D : Constructors can have at most five default parameters.

5. Where the default value of parameter have to be specified?

Options

A : Function call

B : Function definition

C : Function prototype

D : Both B or C

6. Which of the following function prototype is perfectly acceptable?

Options

A : int Function(int Tmp = Show());

B : float Function(int Tmp = Show(int, float));

C : Both A and B.

D : float = Show(int, float) Function(Tmp);

7. Which of the following function / types of function cannot have default parameters?

Options

A : Member function of class

B : main()

C : Member function of structure

D : Both B and C

8. Which of the following statement is correct about the program given below? #include<iostream.h> static int Result; class India { public: void Change(int x = 10, int y = 20, int z = 30) { cout<< x + y + z; } void Display(int x = 40, float y = 50.00) { Result = x % x; cout<< Result; } }; class CuriousTab { int x, y; public: void Change(int x, int y = 50) { cout<< x + y; } }; class CuriousTab: public India, public CuriousTab { public: void Display(int x = 10, int xx = 100, int xxx = 1000) { Result = x + xx % x * x; cout<< Result ; } }; int main() { CuriousTab objCuriousTab; objCuriousTab.India::Display(10, 20.00); return 0; }

Options

A : The program will print the output 0.

B : The program will print the output 10.

C : The program will print the output 30.

D : The program will print the output 40.

Options

A : 0

B : 5

C : 100

D : -5

Options

A : 20 10

B : 30 20

C : 20 30

D : 30 40

2. Which of the following statement is correct about the program given below? #include<iostream.h> class CuriousTab { int x, y, z; public: CuriousTab(int x = 100, int y = 30, int z = 0) { this->x = x; this->y = y; this->z = z; Display(); } void Display() { cout<< x << " " << y << " " << z; } }; int main() { int a = 0, b = 1, c = 2; int &x = ++a; int &y = --b; int z = c + b - -c; CuriousTab objCuriousTab(x, y, z); return 0; }

Options

A : The program will print the output 1 0 3.

B : The program will print the output 1 0 4.

C : The program will print the output 1 1 3.

D : The program will print the output 1 1 4.

3. What will be the output of the following program? #include<iostream.h> class TestDrive { int x; public: TestDrive(int xx) { x = xx; } int DriveIt(void); }; int TestDrive::DriveIt(void) { static int value = 0; int m; m = x % 2; x = x / 2; if((x / 2)) DriveIt(); value = value + m * 10; return value; } int main() { TestDrive TD(1234); cout<< TD.DriveIt() * 10 << endl; return 0; }

Options

A : 300

B : 200

C : Garbage value

D : 400

Options

A : 21

B : 22

C : 31

D : 32

6. What will be the output of the following program? #include<iostream.h> class BaseCounter { protected: long int count; public: void CountIt(int x, int y = 10, int z = 20) { count = 0; cout<< x << " " << y << " " << z << endl; } BaseCounter() { count = 0; } BaseCounter(int x) { count = x ; } }; class DerivedCounter: public BaseCounter { public: DerivedCounter() { } DerivedCounter(int x): BaseCounter(x) { } }; int main() { DerivedCounter objDC(30); objDC.CountIt(40, 50); return 0; }

Options

A : 30 10 20

B : Garbage 10 20

C : 40 50 20

D : 20 40 50

8. What will be the output of the following program? #include<iostream.h> void MyFunction(int a, int b = 40) { cout<< " a = "<< a << " b = " << b << endl; } int main() { MyFunction(20, 30); return 0; }

Options

A : a = 20 b = 40

B : a = 20 b = 30

C : a = 20 b = Garbage

D : a = Garbage b = 40

Options

A : 10

B : 20

C : 30

D : 40

Options

A : 8

B : 6

C : -6

D : -8

Options

A : 6

B : 8

C : 9

D : 15

Options

A : 0

B : 314

C : 314.0000

D : 200.0000

Options

A : 237

B : 242

C : 240

D : 35

Options

A : 12 12

B : 12 18

C : 3 14

D : 18 12

6. Which of the following statement is correct about the program given below? #include<iostream.h> const double CuriousTabConstant(const int, const int = 0); int main() { const int c = 2 ; cout<< CuriousTabConstant(c, 10)<< " "; cout<< CuriousTabConstant(c, 20)<< endl; return 0; } const double CuriousTabConstant(const int x, const int y) { return( (y + (y * x) * x % y) * 0.2); }

Options

A : The program will print the output 2 4.

B : The program will print the output 20 40.

C : The program will print the output 10 20.

D : The program will print the output 20 4.50.

Options

A : 65 65 65

B : 65 66 67

C : A A A

D : A B C