Your code has undefined behavior in both cases:
in printf("1: %x \n", next);
you pass a structure where printf
expects an unsigned int
: This has undefined behavior.
in printf("1: %x \n", &next);
you pass a pointer to a structure where printf
expects an unsigned int
. Same problem.
You observe different behavior, but anything could happen.
To print the value of a pointer, use this:
printf("1: %p\n", (void *)&next);
When you pass the structure by value, you cannot print anything because printf
does not handle this data type.
Structures are implemented by the compiler as blocks of sizeof(Point)
bytes with the specified contents. Depending on the context, these blocks may be located in an area of the stack, or stored in one of more registers. If you allocate memory with malloc()
, the block whose address is returned is guaranteed to have the required alignment to store any object type, including all structures.