Home > Back-end >  C language pointer output val=0000000000000001 for help
C language pointer output val=0000000000000001 for help

Time:03-24

#include


A void fun (int *)
{
A=(int *) 3;
}

Int main ()
{
Int * val=(int *) 1;
Fun (val);
Printf (" val=% p \ n ", val);
return 0;
}

This is why the output of val=0000000000000001
??

CodePudding user response:

% p is according to the 32-bit or 64 - bit, hexadecimal output, you modify the pointer in a program's address, the function is still the same address

CodePudding user response:

Because is val (int *) 1 to the fun function in a (local variables), the two variables are independent of each other, in addition to the value, no other relations;

Not so fun function took (int *) 3;
So val or initialized in the main function (int *) 1; The natural result is that,

Can try this
 void fun (int a) * * {
* a=(int *) 3;
}

The

 fun (& amp; Val); 


Then output to the result should be, it is not this,

CodePudding user response:

BTW:
The pointer variable here are in fact play a role of still is a pointer to the ordinary variable, because they were not reference solution,
So the landlord need extra attention, in order to avoid the bus error, pointer variable is actually not random assignment,
  • Related