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