Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Casting a void * to a double segmentation fault

I found the following answer: Convert void* to double

However, I am getting segmetation fault. Why is that?

Code:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

void * p = (void *) 1234;
double n = *(double *)p;

>Solution :

Pointer p is assigned to address 1234 that you chose at random?. You are then referencing a random address. It does not correspond to a valid allocated chunk of memory.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading