Presentation is loading. Please wait.

Presentation is loading. Please wait.

Functions in C Mrs. Chitra M. Gaikwad.

Similar presentations


Presentation on theme: "Functions in C Mrs. Chitra M. Gaikwad."— Presentation transcript:

1 Functions in C Mrs. Chitra M. Gaikwad

2 Functions are small modules in C which perform a particular task with the given parameters.
They provide code reusabiltiy in C A C program is itself a function called as main()

3 There are in built functions and user defined functions
In built functions like printf() and scanf() can be called by including the standard input output library in a C program User defined functions are functions written by the programmer to accomplish the task

4 A function in a C program has three phases:
Function Prototype Function Call Function Declaration

5 Function Definition Function definition has the following syntax:
<return type> <function name>(<parameter list>) { <local declarations> <set of statements> } Return type is the data type of the variable which the function returns to the main function

6 A function name is the name of the function using which it is called in the main()
The parameter list is the list of inputs to be passed to the function Local declaration is declaring variables which will be used in the function only Set of statements are the instructions required to carry out the task

7 Function Call A function call has the following syntax:
<function name>(<argument list>) Argument list is the set of parameters to be passed to the function for processing

8 Function Definition The function definition is the actual code of a function Function definition can be written in main(). In this case there is no need to write the prototype.

9 #include<stdio.h> int area(int); // function prototype void main() // main function { int r, a; // variable declaration printf(“Enter radius of circle”); scanf(“%d”, &r); a=area(r); // function call printf(“Area of the circle is: %d”,a); } int area(int a) int a1; // local variable a1= 3.14*a*a; // Computing area of a circle return (a); // returning value of area to the main function


Download ppt "Functions in C Mrs. Chitra M. Gaikwad."

Similar presentations


Ads by Google