Sie sind auf Seite 1von 9

Function Assignment-2

1. Which of the following permits function overloading on c++?


a) type
b) number of arguments
c) both of the mentioned
d) none of the mentioned
Answer:

2. In which of the following we cannot overload the function?


a) return function
b) caller
c) called function
d) none of the mentioned
Answer

3. Function overloading is also similar to which of the following?


a) operator overloading
b) constructor overloading
c) destructor overloading
d) none of the mentioned
Answer:

4. What is the output of this program?


#include <iostream>
using namespace std;
void print(inti)
{
cout<<i;
}
void print(double f)
{
cout<< f;
}
int main(void)
{
print(5);
print(500.263);
return 0;
}

a) 5500.263
b) 500.2635
c) 500.263
d) none of the mentioned
Answer:
5 Overloaded functions are
a) Very long functions that can hardly run
b) One function containing another one or more functions inside it.
c) Two or more functions with the same name but different number of parameters or type.
d) none of the mentioned
Answer:

6. What will happen while using pass by reference


a) The values of those variables are passed to the function so that it can manipulate them
b) The location of variable in memory is passed to the function so that it can use the same
memory area for its processing
c) The function declaration should contain ampersand (& in its type declaration)
d) All of the mentioned
Answer:

7. When our function doesn’t need to return anything means what we will as parameter in
function?
a) void
b) blank space
c) both a & b
d) none of the mentioned
Answer:

8. What are the advantages of passing arguments by reference?


a) Changes to parameter values within the function also affect the original arguments.
b) There is need to copy parameter values (i.e. less memory used)
c) There is no need to call constructors for parameters (i.e. faster)
d) All of the mentioned
Answer:

9. Where does the execution of the program starts?


a) user-defined function
b) main function
c) void function
d) none of the mentioned
Answer:

10. What are mandatory parts in function declaration?


a) return type,function name
b) return type,function name,parameters
c) both a and b
d) none of the mentioned
Answer:
11. What is the output of this program?

#include <iostream>
using namespace std;
void copy (int& a, int& b, int& c)
{
a *= 2;
b *= 2;
c *= 2;
}
int main ()
{
int x = 1, y = 3, z = 7;
copy (x, y, z);
cout<< "x =" << x << ", y =" << y << ", z =" << z;
return 0;
}
a) 2 5 10
b) 2 4 5
c) 2 6 14
d) none of the mentioned

Answer:
12. How many maximum number of arguments can be present in function in c99 compiler?
a) 99
b) 90
c) 102
d) 127
Answer:

13. Which is more effective while calling the functions?


a) call by value.
b) call by reference
c) call by pointer
d) none of the mentioned
Answer

14. What is the output of this program?


#include <iostream>
voidmani()
voidmani()
{
cout<<"hai";
}
int main()
{
mani();
return 0;
}
a) hai
b) haihai
c) compile time error
d) none of the mentioned
Answer:

15. What is the output of this program?


#include <iostream>
using namespace std;
void fun(int x, int y)
{
x = 20;
y = 10;
}
int main()
{
int x = 10;
fun(x, x);
cout<< x;
return 0;
}
a) 10
b) 20
c) compile time error
d) none of the mentioned
Answer:
16. What is the scope of the variable declared in the user defined function?
a) Whole program
b) only inside the {} block
c) both a and b
d) none of the mentioned
Answer:

17. How many minimum numbers of functions are need to be presented in C++?
a) 0
b) 1
c) 2
d) 3

Answer:

18. Which of the following function prototype is perfectly acceptable?

a) int Function(intTmp = Show());


b) float Function(intTmp = Show(int, float));
c) Both A and B.
d) float = Show(int, float) Function(Tmp);
Answer:

19. Which of the following statement is correct?


a) C++ enables to define functions that take constants as an argument.
b) We cannot change the argument of the function that that are declared as constant.
c) Both A and B.
d) We cannot use the constant while defining the function.
Answer:

20. Which of the following statement is correct?


a) Overloaded functions can have at most one default argument.
b) An overloaded function cannot have default argument.
c) All arguments of an overloaded function can be default.
d) A function if overloaded more than once cannot have default argument.
Answer:

21. Which of the following statement is correct?


a) Two functions having same number of argument, order and type of argument can be
overloaded if both functions do not have any default argument.
b) Overloaded function must have default arguments.
c) Overloaded function must have default arguments starting from the left of argument list.
d) A function can be overloaded more than once.
Answer:
22. What is the output of this program?

#include <iostream>
using namespace std;
int max(int a, int b )
{
return ( a > b ? a : b );
}
int main()
{
inti = 5;
int j = 7;
cout<< max(i, j );
return 0;
}
a) 5
b) 7
c) either 5 or 7
d) none of the mentioned
Answer:
23. Which of the following function / type of function cannot be overloaded?
a) Member function
b) Static function
c) Virtual function
d) Both B and C
Answer:
24. Which of the following function declaration is/are incorrect?
a) int Sum(int a, int b = 2, int c = 3);
b) int Sum(int a = 5, int b);
c) int Sum(int a = 0, int b, int c = 3);
d) Both B and C are incorrect.
e) All are correct.
Answer:
25. Which of the following statement is incorrect?
a) The default value for an argument can be a global constant.
b) The default arguments are given in the function prototype.
c) Compiler uses the prototype information to build a call, not the function definition.
d) The default arguments are given in the function prototype and should be repeated in the
function definition.
Answer:
26.Implementation of friend function
#include<iostream.h>
#include<conio.h>
class base {
int val1, val2;
public:

void get() {
cout<< "Enter two values:";
cin>> val1>>val2;
}
friend float mean(base ob);
};

float mean(base ob) {


return float(ob.val1 + ob.val2) / 2;
}
void main() {
clrscr();
baseobj;
obj.get();
cout<< "\n Mean value is : " << mean(obj);
getch();
}

27. Program for Factorial Value Using Function In C++.


#include<iostream>
#include<conio.h>
//Function
long factorial(int);

int main() {

// Variable Declaration
int counter, n;

// Get Input Value


cout<< "Enter the Number :";
cin>>n;

// Factorial Function Call


cout<< n << " Factorial Value Is " << factorial(n);

// Wait For Output Screen


getch();
return 0;
}
// Factorial Function
long factorial(int n) {
int counter;
long fact = 1;

//for Loop Block


for (int counter = 1; counter <= n; counter++) {
fact = fact * counter;
}
return fact;
}

28. Inline function Implementation


#include<iostream.h>
#include<conio.h>

class line {
public:
inline float mul(float x, float y) {
return (x * y);
}
inline float cube(float x) {
return (x * x * x);
}
};
void main() {
lineobj;
float val1, val2;
clrscr();
cout<< "Enter two values:";
cin>> val1>>val2;
cout<< "\nMultiplication value is:" <<obj.mul(val1, val2);
cout<< "\n\nCube value is :" <<obj.cube(val1) << "\t" <<obj.cube(val2);
getch();
}

29. Implementation of Library function


#include <iostream>
#include <cmath>

using namespace std;

int main()
{
double number, squareRoot;
cout<< "Enter a number: ";
cin>> number;

// sqrt() is a library function to calculate square root


squareRoot = sqrt(number);
cout<< "Square root of " << number << " = " <<squareRoot;
return 0;
}
30.Implementation of function overloading.
#include <iostream>
using namespace std;

void display(int);
void display(float);
void display(int, float);

int main() {

int a = 5;
float b = 5.5;

display(a);
display(b);
display(a, b);
return 0;
}

void display(intvar) {
cout<< "Integer number: " <<var<<endl;
}

void display(float var) {


cout<< "Float number: " <<var<<endl;
}

void display(int var1, float var2) {


cout<< "Integer number: " << var1;
cout<< " and float number:" << var2;
}

Das könnte Ihnen auch gefallen