0 ratings0% found this document useful (0 votes) 31 views5 pages10th Comp CH 5 Exercise
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content,
claim it here.
Available Formats
Download as PDF or read online on Scribd
INOTES: 1@TH COMPUTER - UNIT 5 - EXERCISE]
QL. Multiple Choice Questions
1) Functions could be built-in or.
a. Admin defined b. server defined
©. User defined 4d Botha and c
2) The functions which are available in C Standard Library are, called
a. User-defined b. Built-in
c. Recursive 4. Repetitive
3) The values passed to a function are called
a. Bodies b, Return types
c. Arrays 4. Arguments
4) char ed( {return ‘a°} . In this function "char" is
a. Body b, Return type
©. Array 4. Arguments
5) The advantages of using funetions are
a. Readability b. Reusability
c. Fasy debugging, aatl
6) If there are three return statements in the function body, of them will be executed.
a. One b. Two
©. Three First and Last
7) Readability helps to the code.
a. Understand b. Modify ¢. Debug all
8) means to transfer the control to another funetion.
a. Calling b, Defining c. Re-writing Including
Answers
Le 2b 3.d 4b
5.d 6a 7d Ra
Q2. Define the following terms.
1) Fune
Function
A funtion is a block of statements that performs a particular task. A program can have
‘many functions. Each function in the program must have a unique name.A type of function that is available in C Standard Library is called built-in function or
library function. These functions are predefined in C language. Built-in functions make
programming faster and easier.
3) Functions Parameters
‘The variables in the function definition that receive the values are called parameters.
The values of arguments are copied to parameters when a function is called. The function does
not make any change to the values of the arguments.
4) Reusability
‘The code in a function is written once but can be reused many times. It allows the user
to execute the same statements mul
jout writing it again. Suppose a function Line
displays a line on the screen. It can be executed in different parts of the program to display the
line again and again.
5) Calling a function
The statement that activates a function is known as function call. A function is called
with its name, When a function is called, the following steps take place:
1. The control moves to the function that is called.
2. All statements in the funetion body are executed,
3. The control returns back to the calling function.
When the control returns back to the calling function, the remai
calling function are executed.
ing statements in the
Q3. Briefly answer the following questions:
1. What is difference between arguments and parameters? Give an example.
Ans: The values that are passed to a function are called arguments. The variables in the
function definition that receive the values are called parameters. The values of
arguments are copied to parameters when a function is called.
void fun(int a)
t
printf("6d", a):
}
void main()
t
fun(5);,
3
In the above example, the value 5 in function call is the argument. The variable a in
the fiznction fun is the parameter.2. Enlist the parts of a function definition,
Ans: ‘Two parts of a function definition include the function header and funetion body. The
fimetion header indicates the return-type, function-name and arguments, Function body
contains the set of statements which are executed in the function.
n call?
3. Isit necessary to use compatible data types in function definition and func
Justify your answer with an exampl
Ans: Yes, itis necessary to use compatible data types in the funetion defi
function call. The program may produce wrong output if the data types in function
definition and function call are different
void fun(int a)
jon and the
printf
main()
fun(2.5);
In the above example, the data type in fumetion definition is int but the fumetion call
contains a float data, ‘The program will display the value 2 instead of 2.5.
4. Describe the advantages of using functions.
Ans: See Long Q
‘5. What do you know about the return keyword?
Ans: The keyword return is used to retum the value back to the calling fisnction, The control
moves back to the calling function along with the retumed value when the return
statement is executed in a function.
Q4. Ident
a
errors in the following coding segments.
void sum (int a, int b)
t
return a+b;
3
Ans: The return type of the function should be int.
b.
void message (0);
f
printf("Hope you are fine :)");
return 23;
3
Ans: 1. The semicolon at the end of first line is invalid.
2. The return type of the function should be int.e
int max (int a; int b)
t
it(@>b)
return as
return b;
$
Ans: The semicolon in the first line must be replaced with comma,
int product (int ni, int n2)
return nl * n2;
Ans: The statement return nl * n2; must be enclosed in curly braces {}.
e
int totalDigits (int x)
{
int count = 0;
for (int >,
count++5,
return count
2. The semicolon after the function body must be removed.
Q5. Write down the output of the following code segment.
a
int xyz (int n)
t
return n +n;
3
int main( )
t
int p= xyz(5);
P= xyz(p);
printf ("%6dl", p);
3
Ans: 20
b.
void abe (int a, int b, int ©)
t
int sum =a* bc
3
int main ()
t
in third line must be replaced with semicolon.int x = 4, y =7, 2 =23, sum1=0;
abe (x, y, 2);
printf" %d %d %d", x, y. 2):
}
Ans: 4723
©
int aa (int x)
t
int p=x/ 10;
x
P= p+(P*x),
return p:
3
int main ()
{
printf("We got %d", aa(aa(23)));
3
Ans: We got 260
a
float £3(int nl, int n2)
t
nl=nl +n2;
n2=n2-nl;
return 0;
3
int main ()
t
printf("%efin", £3(3,2)):
prinfi("%ofin ", £3(10,6));
}
Ans: 0.000000
0.000000
at : freeilm786@ gmail.com
visit: freeilm.com