Home > Back-end >  Questions about C language array as a function of parameters for help
Questions about C language array as a function of parameters for help

Time:09-30



Turn to

Questions about C language array as a function of parameters:
As shown in figure, print out the array arr address in the function fun, why and in the main array of print address different?

The code is as follows:
 
#include

Void fun (int arr [], int len)
{
Arr [0]=2;
Printf (" addr_in_fun: % p \ n ", & amp; Arr);
}

Int main ()
{
Int arr [2]={0};

Fun (arr, 2);

Printf (" % d \ n ", arr [0]).

Printf (" addr_in_main: % p \ n ", & amp; Arr);

Printf (" addr_0: % p ", & amp; Arr [0]);

return 0;
}


Thank you very much ~

CodePudding user response:

You put in front of arr & amp; Remove the same

CodePudding user response:

Back into a pointer array into functions, arr entered the fun becomes int x
So & amp; Arr is int * * and arr is not a thing, is not the same as the address nature

CodePudding user response:

Each function call, to recreate the function of the tangible, passed by the compaction joining will initialize the corresponding parameter,
Please refer to "function in c + + array parameter"
Wish I could help you

CodePudding user response:

refer to the second floor truth is right or wrong response:
array into function back into a pointer, arr entered the fun becomes int x
So & amp; Arr is int * * and arr is not a thing, the address is not the same as the natural

Thank you
Could you tell me why in the main function,
 printf (" addr_in_main: % p \ n ", & amp; Arr); 

Print is arr [0] address?

CodePudding user response:

Because he is an array in the main function
  • Related