Programs

Question 6 :

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

#include < iostream . h > 
int main()
{
    int x = 10, y = 20;
    int *ptr = &x;
    int &ref = y;

    *ptr++;
     ref++;    

    cout<< x << " " << y;
    return 0; 
}


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

Question 7 :

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

#include < iostream . h > 
int main()
{
    int x = 0;
    int &y = x; y = 5; 
    while(x <= 5)
    {
        cout<< y++ << " ";
        x++;
    }
    cout<< x; 
    return 0; 
}


A). The program will print the output 5 6 7 8 9 10.
B). The program will print the output 5 6 7 8 9 10 7.
C). The program will print the output 5 7.
D). It will result in a compile time error.
Answer : Option C

Question 8 :

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

#include < iostream . h > 
int main()
{
    int m = 2, n = 6;
    int &x = m;
    int &y = n;
    m = x++; 
    x = m++;
    n = y++;
    y = n++;
    cout<< m << " " << n; 
    return 0; 
}


A). The program will print output 2 6.
B). The program will print output 3 7.
C). The program will print output 4 8.
D). The program will print output 5 9.
E). The program will print output 6 10.
Answer : Option C

Question 9 :

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

#include < iostream . h > 
int main()
{
    int m = 2, n = 6;
    int &x = m++;
    int &y = n++;
    m = x++; 
    x = m++;
    n = y++;
    y = n++;
    cout<< m << " " << n; 
    return 0; 
}


A). The program will print output 3 7.
B). The program will print output 4 8.
C). The program will print output 5 9.
D). The program will print output 6 10.
E). It will result in a compile time error.
Answer : Option E

Question 10 :

What will be the output of the following program?

#include < iostream . h > 
class ParinamTest
{
    public:
    ParinamTest(int &x, int &y)
    {
        x++;
        y++;
    } 
};
int main()
{
    int a = 10, b = 20;
    ParinamTest objBT(a, b); 
    cout<< a << " " << b; 
    return 0; 
}


A). 10 20
B). 11 21
C). Garbage Garbage
D). It will result in a compile time error.
Answer : Option B