Pages

This blog is under construction

Friday, December 21, 2018

What are the functions in C programming?


A function is a module or block of program code which deals with a particular task. Making functions is a way of isolating one block of code from other independent blocks of code.
How function work in c:

Advantages of function:
1. The program will be easier to understand, maintain and debug.
2. Reusable codes that can be used in other programs
3. A large program can be divided into smaller modules. Hence, a large project can be divided among many programmers.

Function signatures are the "declaration" of the functions in a program. Declaration of a function instructs a compiler on how to call a function. Function declarations comprise of the following:
1. Name of the function
2. Return type : type of the value that will be returned to the program when function is executed
3. Parameter(s) : the type of values that you pass to the function while calling it

Passing Parameters to a Function:
There are two ways to pass parameters to a function:
  • Pass by Value: mechanism is used when you don't want to change the value of passed parameters. When parameters are passed by value then functions in C create copies of the passed in variables and do required processing on these copied variables.
  • Pass by Reference mechanism is used when you want a function to do the changes in passed parameters and reflect those changes back to the calling function. In this case only addresses of the variables are passed to a function so that function can work directly over the addresses.
 Types of User-defined Functions:
  • Function with no arguments and no return value
  • Function with no arguments and a return value
  • Function with arguments and no return value
  • Function with arguments and a return value

No comments:

Post a Comment