84.4k views
5 votes
What is difference between actual parameters and formal parameters in java?​

2 Answers

6 votes
/ * The prototype of the function, here it is declared, only the data type of its parameters, name and return type are indicated. Now it will be visible anywhere in the program. * /
void function (int, double);

int main ()
{
int x = 10;
double y = 25.56;

function (x, y); // Call the function to which the actual parameters x and y are passed
return 0;
}

/ * Function definition. Contains formal parameters a and b. When the function is called, they will be replaced by the actual parameters, in this case x and y, respectively. * /
void function (int a, double b)
{
// The body of the function, contains the function code.
}
User Kyuuuyki
by
5.4k points
5 votes
1> the parameters used in prototypes and function definitions are called formal parameters and

2>those used in function calls are called actual parameters.actual parameters used in a calling statement may be simple constants.

EXAMPLE: int main()

{

int a,b,c;

int add(int,int);

c=add(a,b);//actual parameter printf("%d",c);

getch();

}

int add(int e,int f) //formal parameter { printf("enter the no");

scanf("%d%d",&e,&f);

return e+f;

}
Tell me if it works or did I explain it.
User Chinthaka
by
4.9k points