adplus-dvertising

Welcome to the Functions in C++ MCQs Page

Dive deep into the fascinating world of Functions in C++ with our comprehensive set of Multiple-Choice Questions (MCQs). This page is dedicated to exploring the fundamental concepts and intricacies of Functions in C++, a crucial aspect of Object Oriented Programming Using C++. In this section, you will encounter a diverse range of MCQs that cover various aspects of Functions in C++, from the basic principles to advanced topics. Each question is thoughtfully crafted to challenge your knowledge and deepen your understanding of this critical subcategory within Object Oriented Programming Using C++.

frame-decoration

Check out the MCQs below to embark on an enriching journey through Functions in C++. Test your knowledge, expand your horizons, and solidify your grasp on this vital area of Object Oriented Programming Using C++.

Note: Each MCQ comes with multiple answer choices. Select the most appropriate option and test your understanding of Functions in C++. You can click on an option to test your knowledge before viewing the solution for a MCQ. Happy learning!

Functions in C++ MCQs | Page 23 of 30

Explore more Topics under Object Oriented Programming Using C++

Q221.
What will be the output of the following program?
#include<iostream.h> 
class Bits
{
    int x, y; 
    public:
    void show(void);
    void main(void);
};
void Bits::show(void)
{ 
    Bits b;
    b.x = 2;
    b.y = 4;
    cout<< x << " " << y;
}
void Bits::main(void)
{
    Bits b;
    b.x = 6; 
    b.y = 8;
    b.show();
}
int main(int argc, char *argv[])
{
    Bits run;
    run.main();
    return 0; 
}
Discuss
Answer: (b).6 8
Q222.
Which of the following statement is correct about the program given below?
#include<iostream.h> 
class CompscibitsSample
{
    private:
    int AdditionOne(int x, int y = 1) 
    {
        return x * y;
    }
     
    public:
    int AdditionTwo(int x, int y = 1)
    {
        return x / y;
    } 
}; 
int main()
{
    CompscibitsSample objBits;
    cout<<objBits.AdditionOne(4, 8)<<" "; 
    cout<<objBits.AdditionTwo(8, 8); 
    return 0;
}
Discuss
Answer: (d).The program will report compile time error.
Q223.
What will be the output of the following program?
#include<iostream.h> 
class Compscibits
{
    int K; 
    public:
    void BitsFunction(float, int , char);
    void BitsFunction(float, char, char);
    
};
int main()
{
    Compscibits objIB;
    objIB.BitsFunction(15.09, 'A', char('A' + 'A'));
    return 0;
}
void Compscibits::BitsFunction(float, char y, char z)
{
    K = int(z);
    K = int(y);
    K = y + z;
    cout<< "K = " << K << endl; 
}
Discuss
Answer: (d).The program will print the output M = -61.
Q224.
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; 
}
Discuss
Answer: (d).400
Q225.
What will be the output of the following program?
#include<iostream.h> 
class Compscibits
{
    int Num; 
    public:
    Compscibits(int x)
    {
        Num = x;
    }
    int BitsFunction(void);
};
int Compscibits::BitsFunction(void)
{
    static int Sum = 0; 
    int Dec;
    Dec = Num % 10; 
    Num = Num / 10; 
    if((Num / 100)) BitsFunction(); 
    Sum  = Sum * 10 + Dec; 
    return Sum;
}
int main()
{
    Compscibits objBits(12345);
    cout<< objBits.BitsFunction();
    return 0; 
}
Discuss
Answer: (c).345
Q226.
What is correct about the following program?
#include<iostream.h> 
class Addition
{
    int x; 
    public: 
    Addition()
    {
        x = 0;
    }       
    Addition(int xx)
    {
        x = xx;
    }
    Addition operator + (int xx = 0)
    {
        Addition objTemp; 
        objTemp.x = x + xx; 
        return(objTemp);
    }
    void Display(void)
    {
        cout<< x << endl;
    }
};
int main()
{
    Addition objA(15), objB;
    objB = objA + 5;
    objB.Display();
    return 0; 
}
Discuss
Answer: (d).Compilation fails due to 'operator +' cannot have default arguments.
Q227.
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; 
}
Discuss
Answer: (a).0
Q228.
What will be the output of the following program?
#include<iostream.h> 
class Compscibits
{
    public: 
    int x, y;
    Compscibits(int xx = 10, int yy = 20)
    {
        x = xx;
        y = yy; 
    }
    void Exchange(int *, int *);
};
int main()
{
    Compscibits objA(30, 40); 
    Compscibits objB(50); 
    objA.Exchange(&objA.x, &objB.y); 
    cout<< objA.x << " " << objB.y << endl; 
    return 0;
}
void Compscibits::Exchange(int *x, int *y)
{
    int t;
    t  = *x;
    *x = *y;
    *y = t ; 
}
Discuss
Answer: (c).20 30
Q229.
Which of the following statement is correct about the program given below?
#include<iostream.h> 
class BitsArray
{
    int Matrix[3][3]; 
    public:
    BitsArray()
    {
        for(int i = 0; i<3; i++)
           for(int j = 0; j < 3; j++) 
              Matrix[j][i] = i + j; 
    }
    void Display(void)
    {
        for(int i = 0; i < 3; i++)
           for(int j = 0; j < 3; j++) 
              cout<< Matrix[j][i] << " "; 
    } 
}; 
int main()
{
    BitsArray objBits;
    objBits.Display();
    return 0; 
}
Discuss
Answer: (b).The program will display the output 0 1 2 1 2 3 2 3 4.
Q230.
What will be the output of the following program?
#include<iostream.h> 
class Compscibits
{
    int x, y, z; 
    public:
    void Apply(int xx = 12, int yy = 21, int zz = 9)
    {
        x = xx;
        y = yy += 10;
        z = x -= 2;
    }
    void Display(void)
    {
        cout<< x << " " << y << endl; 
    } 
    void SetValue(int xx, int yy)
    {
        Apply(xx, 0, yy);
    }
};
int main()
{
    Compscibits *pBits= new Compscibits;
   (*pBits).SetValue(12, 20);
    pBits->Display();
    delete pBits;
    return 0; 
}
Discuss
Answer: (a).10 10

Suggested Topics

Are you eager to expand your knowledge beyond Object Oriented Programming Using C++? We've curated a selection of related categories that you might find intriguing.

Click on the categories below to discover a wealth of MCQs and enrich your understanding of Computer Science. Happy exploring!