ACTUAL AND FORMAL ARGUMENTS

Argument (or parameter) refers to data that is passed to function (function definition) while calling function. Arguments listed in function calling statements are referred to as actual arguments.

These actual values are passed to a function to compute a value or to perform a task. The arguments used in the function declaration are referred as formal arguments. They are simply formal variables that accept or receive the values supplied by the calling function. The number of actual and formal arguments and their data types should be same.

Program to add two integers. Make a function add integers and display sum in main() function.

#include <stdio.h>
int add(int a, int b);
int main()
{
int a,b,sum;
printf("Enters two number to add \n");
scanf("%d %d", &a,&b); //actual arguments
sum=add(a,b);
printf("\n sum=%d", sum);
return 0;
}
int add(int a, int b) //formal arguments
{
int sum;
sum=a+b;
return sum;
}
ACTUAL AND FORMAL ARGUMENTS ACTUAL AND FORMAL ARGUMENTS Reviewed by Unknown on 04:47 Rating: 5

No comments:

Powered by Blogger.