Programs

Question 1 :

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

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


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

Question 2 :

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

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


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

Question 3 :

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

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


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

Question 4 :

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

#include < iostream . h > 
int main()
{
    int x = 10;
    int &y = x;
    x = 25;
    y = 50;
    cout << x << " " << --y;
    return 0; 
}


A). The program will print the output 25 49.
B). It will result in a compile time error.
C). The program will print the output 50 50.
D). The program will print the output 49 49.
Answer : Option D

Question 5 :

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

#include < iostream . h > 
enum Parinam
{
    a=1, b, c
};
int main()
{
    int x = c;
    int &y = x;
    int &z = x;
    y = b;
    cout<< z--;
    return 0; 
}


A). It will result in a compile time error.
B). The program will print the output 1.
C). The program will print the output 2.
D). The program will print the output 3.
Answer : Option C

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

Question 11 :

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

#include < iostream . h > 
enum xyz
{
    a, b, c
};
int main() 
{
    int x = a, y = b, z = c;
    int &p = x, &q = y, &r = z;
    p = ++x;
    q = ++y;
    r = ++c;
    cout<< p << q << r;
    return 0;
}


A). The program will print the output 1 2 3.
B). The program will print the output 2 3 4.
C). The program will print the output 0 1 2.
D). It will result in a compile time error.
Answer : Option D

Question 12 :

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

#include < iostream . h > 
int main()
{
    int arr[] = {1, 2 ,3, 4, 5}; 
    int &zarr = arr;
    for(int i = 0; i <= 4; i++)
    {
        arr[i] += arr[i];
    }
    for(i = 0; i <= 4; i++)
        cout<< zarr[i]; 
    return 0; 
}


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

Question 13 :

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

#include < iostream . h > 
struct Parinam
{
    short n;
};
int main()
{
    Parinam b;
    Parinam& rb = b;
    b.n = 5;
    cout << b.n << " " << rb.n << " ";
    rb.n = 8;
    cout << b.n << " " << rb.n;
    return 0; 
}


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

Question 14 :

What will be the output of the following program?

#include  < iostream . h > 
enum xyz 
{
    a, b, c
}; 
int main()
{
    int x = a, y = b, z = c; 
    int &p = x, &q = y, &r = z; 
    p = z; 
    p = ++q;
    q = ++p;
    z = ++q + p++; 
    cout<< p << " " << q << " " << z;
    return 0; 
}


A). 2 3 6
B). 4 4 7
C). 4 5 8
D). 3 4 6
Answer : Option B

Question 15 :

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

#include < iostream . h > 
int ParinamFunction(int m)
{
    m *= m;
    return((10)*(m /= m)); 
}
int main()
{
    int c = 9, *d = &c, e;
    int &z = e;
    e = ParinamFunction(c-- % 3 ? ++*d :(*d *= *d));
    z = z + e / 10;
    cout<< c << " " << e;
    return 0;
}


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

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

Question 21 :

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

#include < iostream . h > 
int i, j; 
class IndiaParinam
{
    public:
    IndiaParinam(int x = 0, int y = 0)
    {
        i = x; 
        j = x; 
        Display();
    }
    void Display()
    {
        cout<< j <<" ";
    } 
}; 
int main()
{
    IndiaParinam objParinam(10, 20); 
    int &s = i; 
    int &z = j; 
    i++;
    cout<< s-- << " " << ++z; 
    return 0; 
}


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

Question 22 :

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

#include < iostream . h > 
int x, y; 
class ParinamTest
{
    public:
    ParinamTest(int xx = 0, int yy = 0)
    {
        x = xx;
        y = yy;
        Display(); 
    } 
    void Display()
    {
        cout<< x << " " << y << " ";
    }
};
int main()
{
    ParinamTest objBT(10, 20); 
    int &rx = x; 
    int &ry = y; 
    ry = x;
    rx = y;
    cout<< rx--; 
    return 0; 
}


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

Question 23 :

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

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


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

Question 24 :

What will be the output of the program given below?

#include < iostream . h > 
class ParinamBase
{
    int x;
    public:
    ParinamBase(int xx = 0)
    {
        x = xx; 
    }
    void Display()
    {
        cout<< x ;
    }
};
class ParinamDerived : public ParinamBase
{
    int y; 
    public:
    ParinamDerived(int yy = 0)
    {
        y = yy;
    }
    void Display()
    {
        cout<< y ;
    }
};
int main()
{
    ParinamBase objBase(10); 
    ParinamBase &objRef = objBase;

    ParinamDerived objDev(20); 
    objRef = objDev;

    objDev.Display(); 
    return 0; 
}


A). 0
B). 10
C). 20
D). Garbage-value
E). It will result in a compile-time/run-time error.
Answer : Option C

Question 25 :

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

#include < iostream . h > 
class IndiaParinam
{
    int x, y; 
    public:
    IndiaParinam(int xx = 0, int yy = 0)
    {
        x = xx; 
        y = yy;
    }
    void Display()
    {
        cout<< x << " " << y;
    }
    IndiaParinam operator +(IndiaParinam z)
    {
        IndiaParinam objTemp;
        objTemp.x = x + z.x;
        objTemp.y = y + z.y;
        return objTemp; 
    }
};
int main()
{
    IndiaParinam objParinam1(90, 80); 
    IndiaParinam objParinam2(10, 20); 
    IndiaParinam objSum; 
    IndiaParinam &objRef = objSum; 
    objRef = objParinam1 + objParinam2; 
    objRef.Display(); 
    return 0; 
}


A). It will result in a runtime error.
B). It will result in a compile time error.
C). The program will print the output 9 4.
D). The program will print the output 100 100.
Answer : Option D