Functions II-227
44. Choose correct o/p option.
int fun()
{
printf("Hi ");
return 0;
printf("Hello ");
return 23;
}
void main()
{
int i;
clrscr();
i = fun();
printf(" %d ",i) ;
getch();
}
The output is
(a) Hi 0 Hello 23 (b) Hi Hello 0 23
(c) Hi 0 (d) Hi 23
Answers
1. (a) 2. (a) 3. (a) 4. (a) 5. (a) 6. (a) 7. (a) 8. (a) 9. (a) 10. (b) 11. (a)
12. (a) 13. (b) 14. (a) 15. (a) 16. (a) 17. (a) 18. (a) 19. (a) 20. (a) 21. (a) 22. (b)
23. (b) 24. (a) 25. (c) 26. (b) 27. (c) 28. (a) 29. (b) 30. (b) 31. (a) 32. (a) 33. (b)
34. (a) 35. (b) 36. (b) 37. (b) 38. (a) 39. (b) 40. (a) 41. (c) 42. (b) 43. (d) 44. (c)
True or False
1. Every ‘C’ program starts with function main().
2. Library function can be defined by the user.
3. User-defined functions have serious limitations.
4. The sum() is a standard library function.
5. The abs() is a standard library function.
6. The abs() gives absolute value.
7. Mathematical library functions are defined in math.h.
8. Functions not returning any value are known as void.
9. The return() statement can return more than one value at a time.
10. The arguments of function which are invoked are called actual arguments.
M10_ITL-ESL4791_02_SE_C10.indd 227 12/22/2012 5:01:43 PM
II-228 Programming Concepts
11. A user-defined function cannot call another user-defined function.
12. A user-defined function cannot call a main() function.
13. The scope of local variables is limited to the block in which they are defined.
14. Actual and formal arguments can have same variable name.
15. In call by value, values are passed to formal arguments.
16. In call by address, formal arguments are pointer to actual arguments.
17. A change made in formal arguments can change the value of variable permanently.
18. A function prototype gives information in advance to the compiler.
19. A function can pass arguments to another function.
20. The data type before the function name indicates the type of value the function will return.
21. By default, function returns integer value.
22. When a function calls itself, the process is called recursion.
23. Like variable, functions also have address in the memory.
24. Functions can be invoked using pointers to function.
25. Function prototype is not necessary to match with actual function definition.
Answers
1. True 2. False 3. False 4. False 5. True 6. True 7. True 8. True 9. False
10. False 11. False 12. False 13. True 14. True 15. True 16. True 17. False 18. True
19. True 20. True 21. True 22. True 23. True 24. True 25. False
What is/are the output/s of the following programs?
1.
void main()
{
clrscr();
printf(" India is ");
sub();
getche();
}
sub()
{
printf(" my Country");
}
OUTPUT:
India is my Country
M10_ITL-ESL4791_02_SE_C10.indd 228 12/22/2012 5:01:43 PM
Functions II-229
2.
void main()
{
clrscr();
printf(" India is ");
sub();
secondsub();
printf(" I love my country");
getche();
}
sub()
{
printf(" my Country");
}
secondsub()
{
printf( " ");
}
OUTPUT:
India is my Country
I love my country
3.
void main()
{
clrscr();
sum();
getche();
}
sum()
{
int a=7,f=0,d;
while(a>=1)
{
f=f+a;
a=a-1;
}
printf(" %d",f);
}
OUTPUT:
28
M10_ITL-ESL4791_02_SE_C10.indd 229 12/22/2012 5:01:43 PM
II-230 Programming Concepts
4.
void main()
{
clrscr();
fact();
getche();
}
fact()
{
int a=5,f=1,d;
while(a>=1)
{
f=f*a;
a=a-1;
}
printf(" %d",f);
}
OUTPUT:
120
5.
void main()
{
int a=4,fac;
clrscr();
fac=fact(a);
printf(" %d",fac);
getche();
}
fact(x)
int x;
{
int f=1,d;
while(x>=1)
{
f=f*x;
x=x-1;
}
return(f);
}
OUTPUT:
24
M10_ITL-ESL4791_02_SE_C10.indd 230 12/22/2012 5:01:43 PM
Functions II-231
6.
void main()
{
int a=3,b=4,c=5,d;
clrscr();
mul();
d=a+b+c;
printf(" %d",d);
getche();
}
mul()
{
int a=2,b=3,c=4,d;
d=a*b*c;
printf(" %d",d);
}
OUTPUT:
24
12
7.
#include <stdio.h>
#include <conio.h>
void main()
{
int result;
clrscr();
result=sq();
printf(" Result of function
is= %.2d",result);
getche();
}
sq()
{
int x=2,y=3;
return(x*x+y*y);
}
OUTPUT:
Result of function is = 13
M10_ITL-ESL4791_02_SE_C10.indd 231 12/22/2012 5:01:43 PM
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset