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.
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.
Jackie
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.
Code:#include <cmath> #include <complex> bool euler_flip(bool value) { return std::pow ( std::complex<float>(std::exp(1.0)), std::complex<float>(0, 1) * std::complex<float>(std::atan(1.0) *(1 << (value + 2))) ).real() < 0; }
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); }
hoping to be certified (programming in c)
here's the news - I'm officially certified.