Functions - Programs Multiple Questions and Answers.
Exercise Questions ::
Functions
1. | What will be the output of the program? |
|
#include<iostream.h>
long PAKFunction(int x, int y = 5, float z = 5)
{
return(++x * ++y + (int)++z);
}
int main()
{
cout<< PAKFunction(20, 10);
return 0;
}
|
| A. | 237 |
| B. | 242 |
| C. | 240 |
| D. | 35 |
|
|
Published by:Michael Daani
2. | What will be the output of the following program? |
|
#include<iostream.h>
int PAKFunction(int a, int b = 3, int c = 3)
{
cout<< ++a * ++b * --c ;
return 0;
}
int main()
{
PAKFunction(5, 0, 0);
return 0;
}
|
| A. | -6 |
| B. | -8 |
| C. | 6 |
| D. | 8 |
|
|
Published by:Michael Daani
3. | What will be the output of the 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 |
|
|
Published by:Michael Daani
4. | What will be the output of the program? |
|
#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. |
|
|
Published by:Michael Daani
5. | What will be the output of the 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. | 20 |
| B. | 30 |
| C. | 40 |
| D. | 50 |
|
|
Published by:Michael Daani