## Exercise

1.What is the output of this program?

using namespace std;
void find()
void find()
{
cout<<"course";
}
int main()
{
find();
return 0;
}

A. course
B. coursecourse
C. compile time error
D. none of the mentioned

2.What is the output of this program?

using namespace std;
void fun(int p, int q)
{
p = 20;
q = 10;
}
int main()
{
int p = 10;
fun(p, p);
cout << p;
return 0;
}

A. 10
B. 20
C. compile time error
D. none of the mentioned

3.What is the output of this program?

using namespace std;
void copy (int& a, int& b, int& c)
{
a *= 2;
b *= 2;
c *= 2;
}
int main ()
{
int x = 2, y = 5, z = 7;
copy (x, y, z);
cout << "x =" << x << ", y =" << y << ", z =" << z;
return 0;
}

A. 3 7 10
B. 3 6 5
C. 4 10 14
D. none of the mentioned

4.What is the output of this program?

using namespace std;
void fun(int &p)
{
p = 30;
}
int main()
{
int p = 5;
fun(p);
cout << "New value of p is " << p;
return 0;
}

A. 5
B. 30
C. 15
D. none of the above

5.Which of the following is true about the following program

using namespace std;
long factorial (long p)
{
if (p > 1)
return (p * factorial (p + 1));
else
return (1);
}
int main ()
{
long q = 3;
cout << q << "! = " << factorial ( q );
return 0;
}

A. 6
B. 24
C. segmentation fault
D. compile time error

6.What will be the output of this program?

using namespace std;
void square (int *p)
{
*p = (*p + 1) * (*p);
}
int main ( )
{
int q = 5;
square(&q);
cout << q;
return 0;
}

A. 25
B. compile time error
C. 36
D. 30

7.What will be the output of this program?

using namespace std;
int max(int p, int q )
{
return ( p > q ? p : q );
}
int main()
{
int x = 25;
int y = 50;
cout << max(x, y );
return 0;
}

A. 25
B. 50
C. either 25 or 50
D. none of the mentioned

8. What will be the output of the following program?

using namespace std;
int gcd (int a, int b)
{
int temp;
while (b != 0)
{
temp = a % b;
a = b;
b = temp;
}
return(a);
}
int main ()
{
int x = 7, y = 13;
cout << gcd(x, y);
return(0);
}

A. 7 B. 13 C. 91 D. 1

9. What will be the output of the following program?

using namespace std;
void find(int p)
{
cout << p;
}
void find(double q)
{
cout << q;
}
int main(void)
{
find(5);
find(555.263);
return 0;
}

A. 5555.263
B. 555.2635
C. 555.263
D. None of the mentioned

10. What will be the output of the following program?

using namespace std;
int find (int a, int b)
{
return (a * b);
}
float find (float a, float b)
{
return (a / b);
}
int main()
{
int x = 5, y = 2;
float n = 5.0, m = 2.0;
cout << find(x, y) <<"\t";
cout << find (n, m);
return 0;
}

A. 10.0 5.0
B. 5.0 2.5
C. 10.0 5
D. 10 2.5

11. A function abc is defined as
void abc(int x=0, int y, int z=0)
{
cout << x << y << z;
}
Which of the following function calls is/are illegal? (Assume h, g are declared as integers)

A. abc () ;
B. abc (h) ;
C. abc (h,h) ;
D. Both A and B

12.
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

A. It results in compile-time error
B. It results in run time error
C. It prints 1 1 2
D. It prints 1 1 1

13.
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

A. It results in compile-time error
B. It results in run time error
C. It prints 1 1 2
D. It prints 1 1 10

14.
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

A. It results in compile-time error
B. It results in run time error
C. It prints 1 1 2
D. It prints 1 1 10