Programs

Question 16 :

Which of the following statement is correct about the program given below?

#include < iostream . h > 
class Parinam
{
    int x, y; 
    public:
    Parinam(int x, int y)
    {
        this->x = x;
        this->y = y;
    }
    void Display()
    {
        cout<< x << " " << y;
    }
};
int main()
{
    int x = 50;
    int &y = x ;
    Parinam b(y, x);
    return 0; 
}


A). The program will print the output 50 50.
B). The program will print the two garbage values.
C). It will result in a compile time error.
D). The program will print nothing.
Answer : Option D

Question 17 :

Which of the following statement is correct about the program given below?

#include < iostream . h > 
class IndiaParinam
{
    int x, y; 
    public:
    void SetValue(int &xx, int &yy)
    {
        x =  xx++;
        y =  yy; 
        cout<< xx << " " << yy;
    }
};
int main()
{
    int x = 10;
    int &y = x;
    IndiaParinam objParinam;
    objParinam.SetValue(x , y);
    return 0; 
}


A). The program will print the output 10 10.
B). The program will print the output 10 11.
C). The program will print the output 11 10.
D). The program will print the output 11 11.
E). It will result in a compile time error.
Answer : Option D

Question 18 :

Which of the following statement is correct about the program given below?

#include < iostream . h > 
class IndiaParinam
{
    int x, y; 
    public:
    void SetValue(int &a, int &b)
    {
        a = 100;
        x = a;
        y = b;
        Display();
    }
    void Display()
    {
        cout<< x << " " << y; 
    }
};
int main()
{
    int x = 10;
    IndiaParinam objParinam;
    objParinam.SetValue(x, x);
    return 0;
}


A). The program will print the output 100 10.
B). The program will print the output 100 100.
C). The program will print the output 100 garbage.
D). The program will print two garbage values.
E). It will result in a compile time error.
Answer : Option B

Question 19 :

Which of the following statement is correct about the program given below?

#include < iostream . h > 
class IndiaParinam
{
    int x, y; 
    public:
    void SetValue(int &xx, int &yy)
    {
        x =  xx ++;
        y =  yy; 
        Display();
    }
    void Display()
    {
        cout<< x << " " << y;
    }
};
int main()
{
    int x = 10;
    int &y = x;
    IndiaParinam objParinam;
    objParinam.SetValue(x , y);
    return 0; 
}


A). The program will print the output 10 10.
B). The program will print the output 10 11.
C). The program will print the output 11 11.
D). The program will print the output 11 10.
E). It will result in a compile time error.
Answer : Option B

Question 20 :

Which of the following statement is correct about the program given below?

#include < iostream . h > 
class IndiaParinam
{
    int x, y; 
    public:
    IndiaParinam(int &xx, int &yy)
    {
        x = xx;
        y = yy;
        Display();
    }
    void Display()
    {
        cout<< x << " " << y;
    }
};
int main()
{
    int x1 = 10; 
    int &p = x1;
    int y1 = 20; 
    int &q = y1; 
    IndiaParinam objParinam(p, q); 
    return 0; 
}


A). It will result in a compile time error.
B). The program will print the output 10 20.
C). The program will print two garbage values.
D). The program will print the address of variable x1 and y1.
Answer : Option B