.

Data Structures in C++

A data structures is a way of organizing the data to perform the task effectively.

Structure in C++

structure is the user defined data type which holds the address of other data element present in the single variable.

Declaration of structure

The structure must ends with the semicolon to indicate the entity or an object is constructed.

Example

Accessing Structure Members

The member access operator (.) is used to access the member function. This member access is coded between the structure name and structure member that is accessed. When the variable is normal type use struct to member operator and when the variable is pointer type use pointer to member variable.

Structures as Function Arguments

A structure variable is passed to the function with an argument as a normal variable and the structure is passed by value the changes are made to the structure variable which is present inside the function definition that does not reflect the original structure variable.

Example:-

Pointers to Structure

A pointer variable is created not only for the datatypes like int, float, double but they are created for user defined datatypes also.

Example

In the above program a pointer variable ptr and normal variable d of type structure distance is defined. The address of variable d is stored to the pointer variable where ptr is pointing to variable d.

.