hi there,
an array will be passed by using the argument passing, but the array element will not be changed.
this is my instant problem.
thank u buddy.
Printable View
hi there,
an array will be passed by using the argument passing, but the array element will not be changed.
this is my instant problem.
thank u buddy.
Hello jackie,
Could you pls put your code here? let me check it.
b/c i think it should work well.
Tom
void pass_by_value_function( int number);
void pas_by_reference_function( int * number );
int main()
{
int num = 10;
printf("1) Num = %i \n\n",num);
pass_by_value_function( num);
printf("3) Num = %i \n\n",num);
pass_by_reference_function( &num);
printf("5) Num = %i \n\n",num);
getch();
return 0;
}
void pass_by_value_function( int number)
{
number = 200;
printf("2) Num = %i \n\n",num);
}
void pas_by_reference_function( int * number )
{
number = 9999;
printf("4) Num = %i \n\n",num);
}
In other words, pass by reference and the number can be altered, pass by value, and it cannot.
If you wish to pass by reference without changing the value of the variable, copy the initial values into temp variables within the function and change the temp variables.
Hi, hate to do this sabastiani...check code for mistakes.
Code:void pass_by_value_function( int number);
void pas_by_reference_function( int * number );
/* here is a s missing from pas ..minor if typed in a hurry*/
int main()
{
int num = 10;
printf("1) Num = %i \n\n",num);
pass_by_value_function( num);
printf("3) Num = %i \n\n",num);
pass_by_reference_function( &num);
printf("5) Num = %i \n\n",num);
getch();
return 0;
}
/*below num is undeclared in function*/
void pass_by_value_function( int number)
{
number = 200;
printf("2) Num = %i \n\n",num);
}
/* also num undeclared in funct, also misuse of pointers*/
void pas_by_reference_function( int * number )
{
number = 9999;
printf("4) Num = %i \n\n",num);
}
/*this should be
void pass_by_reference(int *number)
{
*number = 9999;
printf("4) Num = %i \n\n", *number);
}