+ 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.
1 Antwort
+ 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;)