Friday, April 19, 2019

Functions

0 comments

Functions: -

 A function self contained subprogram that is meant to do some specific, well define task. C program consist of 1 or more function. A program has only one function then it must be only the main() function.
 C programs have two type a functions.
   1. Library function
   2. User defined function 

Library function:-
 C has the function to provide library function for performing some operation. these function are present in C library and they are predefined
 Example:- square(), power(), printf(), scanf() and so on.

Question:- write a program to find square root of any number

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
# include<studio.h> 
# include< conio.h> 
# include< math.h> 
void main() 
 { 
  clrscr(); 
  int n,s; 
  Printf(" enter any number"); 
  Scanf(" %d",&n); 
  s = square(n); 
  Printf(" the result is =%d",s); 
  getch(); 
 } 

User defined function:-

 Uses can create there own function for performance any specific task of the program. These type function are called user define function. To create and user these function.

We should know about these three things -
First:- function definition
Second:- function declaration
Third:- function call

Function definition:- 
  the function definition the whole description and code of  function. It tells what the function is doing and what are the its inputs and outputs.
Syntax:- return type function_name(argument enter list)
          {
             Local variable declaration;
           {
                Statement;
                 ...........
             }
             Return(expression);
         }

Function declaration:-
 the calling function need information about the called function . If definition of the called function placed before the calling function then declare is not needed.
Syntax: - Return type function_name(argument list)

Function call: -
the function define describe what a function can do, but to actually used it in the program the function should be called some where.
Syntax:- function_name(argument list)

 

 

 

No comments:

Post a Comment