Can you have a pointer to a structure without having an instance of that strucure? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

Can you have a pointer to a structure without having an instance of that strucure?

The second task of 'working with structures in the c tutorial confuses me. Can a pointer point directly to a structure? I thought it only points to instances of a structure, like it can only point to variables of type int and not to int itself.

24th Apr 2019, 2:19 PM
guNo
1 Answer
+ 1
No you cant. Pointers are used to store a memory address of an already allocated block of data. What you see in the exercise is a typed pointer. The same way you can have a pointer to an integer or char, you can have a pointer to struct and then refer to the struct variables using the “arrow” dereference operator (ex. ptr->next;)
25th Apr 2019, 8:42 AM
RollAnd Schullz
RollAnd Schullz - avatar