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

Declaring a pointer to a structure

What’s the difference between

struct point var, *varptr; 

and

struct point *var;

Can we just use the second one without assigning any variable’s address to it?

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 :

The difference is that this statement creates two variables:

struct point var, *varptr;

It has the same effect as using 2 statements:

struct point var; // type struct point
struct point *varptr; // type pointer to struct point

And this statement creates 1 variable:

struct point *var; // type pointer to struct point

Can we just use the second one without assigning any variable’s address to it?

Yes you can use the second one but you would want to initialize it to something (usually another variable’s address) before derefrencing the pointer.

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