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

Dereferencing a struct in C using only its memory address

Suppose the memory address of a struct in C language is stored in a variable of sufficiently wide integer type, such as uintptr_t.
I want to read the contents of struct by casting the integer to a struct pointer and dereferencing that.

Can the original struct be reconstructed using this approach?

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

>Solution :

Instead of storing the memory location in any variable of datatypes like int or uintptr_t, you should simply use pointer to struct. Then the arrow operator can be used to access the content of this struct.
Suppose you have struct named info then pointer can be created as struct info *x = &info;

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