Programs (Set - 1)

Question 1 :

What will be the output of the following program?

#include < iostream . h >
long ParinamFunction(int x, int y = 5, float z = 5)
{
    return(++x * ++y + (int)++z);
}
int main()
{
    cout<< ParinamFunction(20, 10); 
    return 0;
}


A). 237
B). 242
C). 240
D). 35
E). The program will report error on compilation.
Answer : Option A

Question 2 :

What will be the output of the following program?

#include < iostream . h >
int ParinamFunction(int a, int b = 3, int c = 3)
{
    cout<< ++a * ++b * --c ; 
    return 0;
}
int main()
{
    ParinamFunction(5, 0, 0); 
    return 0;
}


A). 8
B). 6
C). -6
D). -8
Answer : Option C

Question 3 :

What will be the output of the following program?

#include < iostream . h > 
void MyFunction(int a, int b = 40)
{
    cout << " a = " << a << " b = " << b << endl;
}
int main()
{
    MyFunction(20, 30);
    return 0; 
}


A). a = 20 b = 40
B). a = 20 b = 30
C). a = 20 b = Garbage
D). a = Garbage b = 40
Answer : Option B

Question 4 :

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

#include < iostream . h > 
static int b = 0; 
void DisplayData(int *x, int *y = &b)
{
    cout<< *x << " " << *y;
}
int main()
{
    int a = 10, b = 20 ;
    DisplayData(&a, &b);
    return 0; 
}


A). The program will print the output 10 20.
B). The program will print the output 10 0.
C). The program will print the output 10 garbage.
D). The program will report compile time error.
Answer : Option A

Question 5 :

What will be the output of the following program?

#include < iostream . h > 
typedef void(*FunPtr)(int);
int Look(int = 10, int = 20);
void Note(int); 
int main()
{
    FunPtr ptr = Note;
    (*ptr)(30); 
    return 0;
}
int Look(int x, int y)
{
    return(x + y % 20);
}
void Note(int x)
{
    cout<< Look(x) << endl;
}


A). 10
B). 20
C). 30
D). 40
E). Compilation fails.
Answer : Option C

Question 6 :

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

#include < iostream . h > 
class IndiaParinam
{ 
    public:
    void Parinam(int x = 15)
    {
        x = x/2; 
        if(x > 0)
            Parinam(); 
        else
            cout<< x % 2; 
    } 
};
int main()
{
    IndiaParinam objIB;
    objIB.Parinam();
    return 0; 
}


A). The program will display 1.
B). The program will display 2.
C). The program will display 15.
D). The program will go into an infinite loop.
E). The program will report error on compilation.
Answer : Option D

Question 7 :

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

#include < iostream . h >
long GetNumber(long int Number)
{
    return --Number;
}
float GetNumber(int Number)
{
    return ++Number;
}
int main()
{
    int x = 20;
    int y = 30;
    cout<< GetNumber(x) << " ";
    cout<< GetNumber(y) ;
    return 0; 
}


A). The program will print the output 19 31.
B). The program will print the output 20 30.
C). The program will print the output 21 31.
D). The program will print the output 21 29.
E). Program will report compile time error.
Answer : Option C

Question 8 :

What will be the output of the following program?

#include < iostream . h > 
struct MyData
{
    public:
    int Addition(int a, int b = 10)
    {
        return (a *= b + 2);
    }
    float Addition(int a, float b);
};
int main()
{
    MyData data;
    cout<< data.Addition(1) <<" ";
    cout<< data.Addition(3, 4);
    return 0; 
}


A). 12 12
B). 12 18
C). 3 14
D). 18 12
E). Compilation fails.
Answer : Option B

Question 9 :

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

#include < iostream . h >
int ParinamTest(int x, int y);
int ParinamTest(int x, int y, int z = 5);
int main()
{
    cout<< ParinamTest(2, 4) << endl; 
    return 0;
}
int ParinamTest(int x, int y)
{
    return x * y;
}
int ParinamTest(int x, int y, int z = 5)
{
    return x * y * z; 
}


A). The program will print the output 5.
B). The program will print the output 8.
C). The program will print the output 40.
D). The program will report compile time error.
Answer : Option D

Question 10 :

What will be the output of the following program?

#include < iostream . h > 
class IndiaParinamSample
{
    public:
        int   a; 
        float b;
        void ParinamFunction(int a, float b, float c = 100.0f)
        {
            cout<< a % 20 + c * --b;
        } 
}; 
int main()
{   IndiaParinamSample objParinam;
    objParinam.ParinamFunction(20, 2.000000f, 5.0f);
    return 0; 
}


A). 0
B). 5
C). 100
D). -5
E). None of these
Answer : Option B

Question 11 :

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

#include < iostream . h >
void Tester(int xx, int yy = 5);
class IndiaParinam
{
    int x; 
    int y; 
    public:
    void Tester(int xx, int yy = 5)
    {
        x = xx;
        y = yy;
        cout<< ++x % --y; 
    }
};
int main()
{
    IndiaParinam objParinam;
    objParinam.Tester(5, 5);
    return 0; 
}


A). The program will print the output 0.
B). The program will print the output 1.
C). The program will print the output 2.
D). The program will print the output garbage value.
E). The program will report compile time error.
Answer : Option C

Question 12 :

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

#include < iostream . h > 
class PowerFinder
{
    public:
    void Power(int x = 1, int y = 1)
    {
        int P = 1, i = 1;
        while(++i <= y)
        {
            P *= x;
        }
        cout<< P << endl; 
    } 
};
int main()
{
    PowerFinder FP; 
    FP.Power(2, 6); 
    return 0;
}


A). The program will print the output 12.
B). The program will print the output 16.
C). The program will print the output 32.
D). The program will print the output 36.
E). The program will execute infinite time.
Answer : Option C

Question 13 :

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

#include < iostream . h >
void Tester(float xx, float yy = 5.0);
class IndiaParinam
{
    float x; 
    float y; 
    public:
    void Tester(float xx, float yy = 5.0)
    {
        x = xx;
        y = yy;
        cout<< ++x % --y; 
    }
};
int main()
{
    IndiaParinam objParinam;
    objParinam.Tester(5.0, 5.0);
    return 0; 
}


A). The program will print the output 0.
B). The program will print the output 1.
C). The program will print the output 2.
D). The program will print the output garbage value.
E). The program will report compile time error.
Answer : Option E

Question 14 :

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

#include < iostream . h >
const double ParinamConstant(const int, const int = 0);
int main()
{
    const int c = 2 ;
    cout<< ParinamConstant(c, 10)<< " "; 
    cout<< ParinamConstant(c, 20)<< endl; 
    return 0;
}
const double ParinamConstant(const int x, const int y)
{
    return( (y + (y * x) * x % y) * 0.2);
}


A). The program will print the output 2 4.
B). The program will print the output 20 40.
C). The program will print the output 10 20.
D). The program will print the output 20 4.50.
E). The program will report compile time error.
Answer : Option A

Question 15 :

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

#include < iostream . h > 
struct MyStructure
{
    class MyClass
    {
        public:
        void Display(int x, float y = 97.50, char ch = 'a')
        {
            cout<< x << " " << y << " " << ch;
        }
    }Cls; 
}Struc;
 
int main()
{
    Struc.Cls.Display(12, 'b');
    return 0; 
}


A). The program will print the output 12 97.50 b.
B). The program will print the output 12 97.50 a.
C). The program will print the output 12 98 a.
D). The program will print the output 12 Garbage b.
E). The program will print the output 12 Garbage a.
Answer : Option C