Can a Structure Contain Pointer to Itself?

You cannot declare a structure type that contains itself as a member, but you can declare a structure type that contains a pointer to itself as a member. The structure tag indicates the data type of the structure variable. The keyword struct is optional in C++.

Can structures have pointers?

The structure pointer points to the address of a memory block where the Structure is being stored. Like a pointer that tells the address of another variable of any data type (int, char, float) in memory.

Can a struct contain a member that has the same type as itself?

The book says, "A structure cannot contain an instance of itself. For example, a variable of type struct employee cannot be declared in the definition for struct employee . A pointer to struct employee, however, may be included."

Sophia Al-Mansoor

Sophia Al-Mansoor

Global Business & E-Commerce Reporter

Sophia analyzes international trade, startup ecosystems, retail transformation, and supply chain logistics for modern digital publications.