C++ Programming MCQ - Functions

11. What is the output of this program?

#include <iostream>
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

View Answer


12. What is the output of this program?

        
Note:Includes all required header files

    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

View Answer


13. What is the output of this program?

       
Note:Includes all required header files 
          
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. x =3, y =7, z =10
B. x =3, y =6, z =5
C. x =4, y =10, z =14
D. None of the above

View Answer


14. What is the output of this program?

        
Note:Includes all required header files

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. New value of p is 5
B. New value of p is 30
C. New value of p is 15
D. None of the above

View Answer


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

Note:Includes all required header files
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

View Answer


16. What will be the output of this program?

        
Note:Includes all required header files
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

View Answer


17. What will be the output of this program?

Note:Includes all required header files
 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

View Answer


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

        
Note:Includes all required header files
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

View Answer


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

#include <iostream>

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

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

View Answer


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

#include <iostream>

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

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

View Answer





Also check :


Discussion


* You must be logged in to add comment.