Function In C Language?

Function in C ?




·      In general we know function as nothing but performing task; this is what exactly function in C language.
·      Function is nothing but a block of statements which perform require task.
·      C is procedure oriented language; Procedure is nothing but a function.
·  In C everything move around function. Unlike java language which focuses on object and classes C focuses on functions.
·   Function is grouped with multiple statements inside it using ‘{‘ and ‘}’ curly brackets.
·      We can use many function in c program.
·      We can divide the problems by writing solution for it using function.
·  There are 3 important steps we have to follow in C program to use function; which are given below:
1.   Function Declaration
2.   Function Definition
3.   Function Calling
·      We will see these 3 steps in detail:
1.   Function Declaration:-
·   Function declaration is nothing but syntactical step where we tell compiler that we are using function with specific return type and arguments.
·    We cannot call any function without declaring it or defining it.
·      Syntax:   return_type function name ( arguments );
·      Ex :- void add();
·    In above syntax  return_type will specify which type of data this function will return.
·  Function_name will be name given to function as per syntax it can be any name we can give.
·  Function name should not start with digits and special symbol.
·      Parenthesis are used to give arguments to the function. It is optional depends on requirements of project.
2.   Function Definition:-
·      This is very important step in which we define what actual task this function has to do and that get done with the help of defining statements.
·  Writing or defining statements within block or scope of function which starts and end within ‘{‘   and   ‘}’ means we are creating/defining function to execute require task.
·    We to do function definition only at once for each function.
·      Ex:-
§  int max(int num1, int num2)
§  {

§     Print(“hi”);

§  }

·    In Above example opening and closing brackets defines the scope of function once compiler reaches to last statement which is closing bracket its closes the function body.
·    Function body is nothing but { } in which we define our statements.

3.   Function Calling:-

·   Function calling is nothing but using our already defined function.
·     This is final step once we defined the function we are ready to use it main().
·      We cannot call function if we not defined it.
·      We have to call function in main() function.
·      Syntax:- function_name(arguments);
·      Ex:- add();
·      In above example we just wrote function name we already defined and putted () without any arguments because we didn’t defined them in function definition or declaration.



Comments

Popular Posts