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.

9. What will be the output of the following program? #include<iostream.h> class CuriousTabSample { public: int a; float b; void CuriousTabFunction(int a, float b, float c = 100.0f) { cout<< a % 20 + c * --b; } }; int main() { CuriousTabSample objCuriousTab; objCuriousTab.CuriousTabFunction(20, 2.000000f, 5.0f); return 0; }

Options

A : 0

B : 5

C : 100

D : -5

10. What will be the output of the following program? #include<iostream.h> class CuriousTab { public: int x, y; CuriousTab(int xx = 10, int yy = 20) { x = xx; y = yy; } void Exchange(int *, int *); }; int main() { CuriousTab objA(30, 40); CuriousTab objB(50); objA.Exchange(&objA.x, &objB.y); cout<< objA.x << " " << objB.y << endl; return 0; } void CuriousTab::Exchange(int *x, int *y) { int t; t = *x; *x = *y; *y = t ; }

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

4. What will be the output of the following program? #include<iostream.h> int main() { float Amount; float Calculate(float P = 5.0, int N = 2, float R = 2.0); Amount = Calculate(); cout<< Amount << endl; return 0; } float Calculate(float P, int N, float R) { int Year = 1; float Sum = 1 ; Sum = Sum * (1 + P * ++N * R); Year = (int)(Year + Sum); return Year; }

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

9. What will be the output of the following program? #include<iostream.h> typedef void(*FunPtr)(int); int Look(int = 10, int = 20); void Note(int); int main() { FunPtr ptr = Note; (*ptr)(30); return 0; } int Look(int x, int y) { return(x + y % 20); } void Note(int x) { cout<< Look(x) << endl; }

Options

A : 10

B : 20

C : 30

D : 40

1. What will be the output of the following program? #include<iostream.h> int CuriousTabFunction(int a, int b = 3, int c = 3) { cout<< ++a * ++b * --c ; return 0; } int main() { CuriousTabFunction(5, 0, 0); return 0; }

Options

A : 8

B : 6

C : -6

D : -8

2. What will be the output of the following program? #include<iostream.h> #include<string.h> class CuriousTab { char txtMsg[50]; public: CuriousTab(char *str = NULL) { if(str != NULL) strcpy(txtMsg, str); } int CuriousTabFunction(char ch); }; int CuriousTab::CuriousTabFunction(char ch) { static int i = 0; if(txtMsg[i++] == ch) return strlen((txtMsg + i)) - i; else return CuriousTabFunction(ch); } int main() { CuriousTab objCuriousTab("Welcome to CuriousTab.com!"); cout<< objCuriousTab.CuriousTabFunction('t'); return 0; }

Options

A : 6

B : 8

C : 9

D : 15

3. What will be the output of the following program? #include<iostream.h> class AreaFinder { float l, b, h; float result; public: AreaFinder(float hh = 0, float ll = 0, float bb = 0) { l = ll; b = bb; h = hh; } void Display(int ll) { if(l = 0) result = 3.14f * h * h; else result = l * b; cout<< result; } }; int main() { AreaFinder objAF(10, 10, 20); objAF.Display(0); return 0; }

Options

A : 0

B : 314

C : 314.0000

D : 200.0000

4. What will be the output of the following program? #include<iostream.h> long CuriousTabFunction(int x, int y = 5, float z = 5) { return(++x * ++y + (int)++z); } int main() { cout<< CuriousTabFunction(20, 10); return 0; }

Options

A : 237

B : 242

C : 240

D : 35

5. What will be the output of the following program? #include<iostream.h> struct MyData { public: int Addition(int a, int b = 10) { return (a *= b + 2); } float Addition(int a, float b); }; int main() { MyData data; cout<<data.Addition(1)<<" "; cout<<data.Addition(3, 4); return 0; }

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.

7. What will be the output of the following program? #include<iostream.h> class Base { public: int S, A, M; Base(int x, int y) { S = y - y; A = x + x; M = x * x; } Base(int, int y = 'A', int z = 'B') { S = y; A = y + 1 - 1; M = z - 1; } void Display(void) { cout<< S << " " << A << " " << M << endl; } }; class Derived : public Base { int x, y, z; public: Derived(int xx = 65, int yy = 66, int zz = 67): Base(x) { x = xx; y = yy; z = zz; } void Display(int n) { if(n) Base::Display(); else cout<< x << " " << y << " " << z << endl; } }; int main() { Derived objDev; objDev.Display(-1); return 0; }

Options

A : 65 65 65

B : 65 66 67

C : A A A

D : A B C

Cpp Programming more Online Exam Quiz

Copyright © 2021
Exam-GK-MCQ-Questions.Com | Contact Us | Privacy Policy | Terms of Use | Sitemap | 0.019989013671875