Function declaration and Prototype



By default, any C function returns an int value. If we want that the function should return a value other than int then we need to explicitly mention it in the function definition. Let us understand this using an example.
Example 1:
float fnGetAverage(int, int); //function prototype
void main(){
int x,y;
float z;
printf(“\nEnter the values for x and y\n”);
scanf(“%d %d”, &x, &y);
z = fnGetAverage(x,y); //function call
printf(“\nThe average is %f”, z);
}
float fnGetAverage(int a, int b){ //function definition
float c;
c = (a+b)/2; //calculating average
return c; //returning the value
}

Output:
Enter the values for x and y
3 2
The average is 2.500000


Responses

0 Respones to "Function declaration and Prototype"

Post a Comment

 

Total Pageviews

Return to top of page Copyright © 2011 | Kuppam Engineering College Converted into Blogger Template by Mohan Murthy