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 24 of 30

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

a.

6

b.

8

c.

9

d.

15

Discuss
Answer: (a).6
Q232.
Which of the following statement is correct about the program given below?
#include<iostream.h>
#include<string.h>
#include<malloc.h>
class BitsString
{
    char txtName[20]; 
    public:
    BitsString(char *txtTemp = NULL)
    {
        if(txtTemp != NULL)
        strcpy(txtName, txtTemp);
    }
    void Display(void)
    {
        cout<<txtName;
    }
};
int main()
{
    char *txtName = (char*)malloc(10);
    strcpy(txtName, "Compscibits");
    *txtName = 48;
    BitsString objTemp(txtName);
    cout<< sizeof(txtName);
    return 0; 
}
Discuss
Answer: (b).Above program will display Compscibits 9.
Q233.
Which of the following statement is correct about the program given below?
#include<iostream.h>
class Compscibits
{
    int x, y, z; 
    public:
    Compscibits(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; 
    Compscibits objBits(x, y, z); 
    return 0; 
}
Discuss
Answer: (b).The program will print the output 1 0 4.
Q234.
Which of the following statement is correct about the program given below?
#include<iostream.h> 
class BitsArray
{
    int array[3][3];
    public:
    BitsArray(int arr[3][3] = NULL)
    { 
        if(arr != NULL)
        for(int i = 0; i < 3; i++) 
            for(int j = 0; j < 3; j++) 
                array[i][j] = i+j; 
    } 
    void Display(void)
    {
        for(int i = 0; i < 3; i++) 
            for(int j = 0; j < 3; j++)
                cout<< array[i][j] << " "; 
    }
};
int main()
{
    BitsArray objBA;
    objBA.Display();
    return 0; 
}
Discuss
Answer: (b).The program will display 9 garbage values.
Q235.
What will be the output of the following program?
#include<iostream.h> 
struct Compscibits
{
    int arr[5]; 
    public:
    void BitsFunction(void);
    void Display(void);
};
void Compscibits::Display(void)
{
    for(int i = 0; i < 5; i++) 
        cout<< arr[i] << " " ;
}
void Compscibits::BitsFunction(void)
{
    static int i = 0, j = 4; 
    int tmp = arr[i]; 
    arr[i]  = arr[j]; 
    arr[j]  = tmp   ; 
    i++;
    j--;
    if(j != i) BitsFunction();
}
int main()
{
    Compscibits objBits = {{ 5, 6, 3, 9, 0 }};
    objBits.BitsFunction();
    objBits.Display();
    return 0; 
}
Discuss
Answer: (a).0 9 3 6 5
Q236.
Which of the following statement is correct about the program given below?
#include<iostream.h> 
class Compscibits
{
    int x; 
    float y; 
    public:
    Compscibits(int x)
    {
        x = x;
    }
    Compscibits(int p = 0, int q = 10)
    {
        x = p += 2; 
        y = q * 1.0f;
    }
    void SetValue(int &y, float z)
    {
        x = y;
        y = (int)z;
    }
    void Display(void)
    {
        cout<< x;
    }
};
int main()
{
    int val = 12; 
    Compscibits objBits(val); 
    Compscibits objTmp();
    objBits.SetValue(val, 3.14f); 
    objBits.Display(); 
    return 0; 
}
Discuss
Answer: (d).The program will not compile successfully.
Q237.
What will be the output of the following program?
#include<iostream.h> 
struct BitsArray
{
    int arr[5]; 
    public:
    void BitsFunction();
    void Display();
};
void BitsArray::BitsFunction()
{
    static int i = 0, j = 4; 
    i++;
    j--;
    if(j > 0)
        BitsFunction(); 
    int tmp = arr[i]; 
    arr[i]  = arr[j]; 
    arr[j]  = tmp; 
    i--;
    j++;
}
void BitsArray::Display()
{
    for(int i = 0; i < 5; i++)
        cout<< arr[i] << " ";
} 
int main()
{
    BitsArray objArr = {{5, 6, 3, 9, 0}};
    objArr.BitsFunction();
    objArr.Display();
    return 0; 
}
Discuss
Answer: (d).0 6 3 9 5
Q238.
What will be the output of the following program?
#include<iostream.h>
#include<string.h> 
class BitsString
{
    char x[50]; 
    char y[50]; 
    char z[50]; 
    public:
    BitsString()
    { }
    BitsString(char* xx)
    {
        strcpy(x, xx); 
        strcpy(y, xx);
    }
    BitsString(char *xx, char *yy = " C++", char *zz = " Programming!")
    {
        strcpy(z, xx); 
        strcat(z, yy); 
        strcat(z, zz);
    } 
    void Display(void)
    {
    cout<< z << endl;
    } 
}; 
int main()
{
    BitsString objStr("Learn", " Java");
    objStr.Display();
    return 0; 
}
Discuss
Answer: (d).Learn Java Programming!
Q239.
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; 
}
Discuss
Answer: (c).40 50 20
Q240.
What will be the output of the following program?
#include<iostream.h> 
class Number
{
    int Num; 
    public:
    Number(int x = 0)
    {
        Num = x;
    }
    void Display(void)
    {
        cout<< Num;
    }
    void Modify(); 
};
void Number::Modify()
{
    int Dec;
    Dec = Num % 13; 
    Num = Num / 13; 
    
         if(Num  > 0 ) Modify()   ; 
         if(Dec == 10) cout<< "A" ; 
    else if(Dec == 11) cout<< "B" ; 
    else if(Dec == 12) cout<< "C" ; 
    else if(Dec == 13) cout<< "D" ;
    else               cout<< Dec ;
}
int main()
{
    Number objNum(130);
    objNum.Modify();
    return 0; 
}
Discuss
Answer: (b).A0

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!