1. I need explanation for void *ptr=value?
The gist of your program is ...
- int *the_data;
-
the_data = (void*)20;
-
printf ("the_data now: %d", *the_data);
Notice that I took some liberties with int* versus void* to enhance clarity. I'm confident that my variant is equivalent to your original program.
Your program
1. Declares the_data as a pointer-to-int.
2. Sets the pointer value to "20". Perhaps this value will look more like an address if I express it in hex: 0x001C.
3. Prints the contents of this_data; that is, the contents of 0x001C.
Notice that there is no variable within your program whose address is 0x001C. That location is outside the domain of your program. What do you expect to find at that location? Perhaps a memory-mapped I/O register, or perhaps a flag set by another thread of execution?
Your program dumps core because the execution environment won't let you access locations that aren't in your program. Not all execution environments are so fastidious. What you're trying to do is not unusual in embedded systems.
One last thought -- whatever you're trying to do; address 0x001C is not written to by your program. You would therefore be strongly advised to declare this_data as follows:
The volatile type qualifier alerts the compiler that accesses to this location must occur precisely as specified in your source code -- the optimizer is not permitted to translate your source code into an equivalent layout.