10th Class Computer New Course Functions Unit-05
Q.1 Multiple choice questions.
- Functions could be built-in or ________________________.
a) admin defined
b) server defined
c) user defined (Correct Answer)
d) Both a and c
2. The functions which are available in C Standard Library are called ________________________.
a) user defined
b) built-in (Correct Answer)
c) recursive
d) repetitive
3. The values passed to a function are called ________________________.
a) bodies
b) return types
c) arrays
d) arguments (Correct Answer)
4. Char cd() {return ‘a’}. In this function “char” is ________________________.
a) body
b) return type (Correct Answer)
c) array
d) arguments
5. The advantages of using functions are ________________________.
a) Readability
b) reusability
c) easy debugging
d) all (Correct Answer)
6. If there are three return statements in the function body, ________________________ of them will be executed.
a) one (Correct Answer)
b) two
c) three
d) first and last
7. Readability helps to ________________________ the code.
a) understand
b) modify
c) debug
d) all (Correct Answer)
8. ________________________ means to transfer the control to another function.
a) Calling (Correct Answer)
b) Defining
c) re-writing
d) Including
Q.2 Define the following.
1) Functions
A function is a block of statements which performs a particular task, e.g. prinf is a function that is used to display anything on computer screen, scanf is another function that is used to take input from the user. Each program has a main function which performs the tasks programmed by the user.
2) Built-in Functions
The functions which are available in C Standard Library are called built-in functions. These functions perform commonly used mathematical calculations, string operations, input/output operations etc.
3) Functions Parameters
Parameters are variables of different data types that are used to receive the values passed to the function as input.
4) Reusability
Function provide reusability of code. It means that whenever we need to use the functionality provided by the function, we just call the function. We do not need to write the same set of statements again and again.
5) Calling a function
Calling a function means to transfer the control to that particular function.
Q.3 Briefly answer the following questions.
1)What is the difference between arguments and parameters? Give an example.
Answer: Difference between arguments and parameters
The values passed to the function are called arguments, whereas variables in the function definition that receive these values are called parameter of the function.
2) Enlist the parts of a function definition.
Answer: Parts of function definition
In C language we have 4 parts while defining a function.
- Return_type (function return a value)
- Function_name (this the name of a function)
- Parameters (a parameter or list of parameters separated by comma)
- Function_body (a statement or collection of statements that defines what the function does.)
So the basic structure of function definition well be as below
Return_type FunctionName(Parameter/list of parameters)
{
Body of the function
}
3) Is it necessary to use compatible data types in function definition and function call? Justify your answer with an example.
Answer:
Yes, it is necessary to use compatible data types in function definition and function call. For example, if we create a function with two parameters x and y where x is integer type and y is float type and when we call that function in the main function and provide the arguments with x as float type and y as integer type then we get the incorrect result as shown in the following program.

4) Describe the advantages of using functions.
Answer: Advantages of using functions
Functions provide us several advantages.
- Reusability: Functions provide reusability of code. It means that whenever we need to use the functionality provided by the function, we just call the function. We do not need to write the same set of statements again and again.
- Separation of tasks: Function allow us to separate the code of one task from the code of other tasks. If we have a problem in one function, then we do not need to check the whole program for removing the problem. We just need to focus at one single function.
- Handling the complexity of the problem: If we write the whole program as a single procedure, management of the program becomes difficult. Functions divide the program into smaller units, and thus reduce the complexity of the problem.
- Readability: Dividing the program into multiple functions, improves the readability of the program.
5) What do you know about the return keyword?
Answer: Return type
Inside the function, return is a keyword that is used to return a value to the calling function.
Q.5 Write down the output of the following code segments.
a. Code

Output

b. Code

Output

c. Code

Output

d. Code

Output

Programming Exercises
Exercise 1: Write a function int square(int x); to calculate the square of an integer x.

Output

Exercise 2: Write a function int power(int x, int y); to calculate and return xy.

Output

Exercise 3: Write a function to calculate factorial of a number.

Output

Exercise 4: Write a function which takes values for three angles of a triangle and prints whether the given values make a valid triangle or not. A valid triangle is the one, where the sum of three angles is equal to 180.

Output

Exercise 5: Write a function which takes the amount and the interest percentage and return the interest amount.

Output

Exercise 7: Write a function to print the table of a number.

Output


10th Class Computer New Course Data & Repetition Unit-04
10th Computer New Course Conditional Logic Unit-03
10th Class Computer New Course User Interaction Unit-02
10th Class Computer New Course ITP Unit-01
9th Computer New Course Designing Website Unit-05
9th Computer New Course Data and Privacy Unit-04
9th Computer New Course Networks Unit-03
9th Computer New Course Binary System Unit-02
9th Computer New Course Problem Solving Unit-01
Buy Best Stationery Products in Pakistan
For more stationery items please visit : https://stationerystore.pk