10th Class Computer Chapter 05 – Functions
Q. No. 1. What is a Function? Describe Different types of Functions with Example.
Ans: Function: A function is a block of statements which performs a particular task, e.g. printf is a function that is used to display anything on the computer screen, similarly scanf is used to take input from the User.
Types of Functions:
1. Built-in-Function: The functions which are available in C standard library are called built-in-functions. For example, printf and scanf are built-in functions.
2. User Defined Function: The Functions which are defined by a programmer to perform a specific task are called user-defined functions. For example,
void test()
{
printf(“I am Mr. Sajid Khan. \n I am student of Class 10th.\n ”)
}
Q. No. 2. Describe Different Advantages of Functions.
Ans: Functions provide us several advantages.
1. Reusability: Functions provide reusability of code. It means that whenever we need to use the functionality provide by the function, we just recall the function.
2. Separation of task: Functions allow us to separate the code of one task from the code of other task. So if we have a problem in program, we will just focus at that single function.
3. Handling the Complex Problem: Functions divide the program into smaller units, and thus reduce the complexity of the problem. Because it is difficult to manage the whole program in a single function.
4. Readability: Dividing the program into multiple functions improves the readability of the program.
Q. No. 3. Describe Signature of Functions.
Ans: Function Signature: It is used to define input and output of a function.
The general structure of function signature is as follow:
return_type function_name(data_type_1… data_type_n)
Function Description | Function Signature |
A function that takes an integer as input and return its square | Int square(int); |
A function that takes length and width of rectangle as input return the perimeters of rectangle | Float perimeter(float, float); |
A function that takes three integers as input and returns the largest value among them | Int largest(int, int, int); |
A function that takes a character as input and returns 1, if the character is vowel, otherwise returns 0. | Int isvowel(char) |
Q. No. 4. Explain Defining a Functions with Example.
Ans: Definition of the function describe, how the function performs the task assigned to it.
The definition of function has following general structure:
return_type function_name(data_type_1… data_type_n)
{
Body of the Function
}
Body of the function: It is the set of statements which are executed in the function to perform the specified task. Just after the function’s signature, the set of statements enclosed inside {} from the body of the function.
Example:
void ShowProgram()
{
printf(“\n Quick Brown Fox Jumps Over The Lazy Dog.\n”);
}
Q. No. 5. Define Arguments and Parameter of the functions.
Ans: Parameters are the variables of different data types of the value returned by function. During the function, the value passed to the function are called arguments. Calling a function means to transfer the control to that particular function.
1 comment