Operations on Structures

In this class, we will try to understand Operations on Structures.

Operations on Structures

We have covered the basics of structures in our previous classes.

Operations on Structures

The image below is the outcome of the structure initialization that we have covered in our previous class.

Operations on Structures Memory for Structure
Memory for Structure

From the above structure, we want to print the stu1 name.

The image below is how we can print.

Operations on Structures Print
Print

In the above image, ‘stu1.name’ uses the dot operator to combine the variable and the member that we want to access.

If we want to change the value of the stu1 number to 256?

The image below is the declaration to assign the values.

Operations on Structures Assignment
Assignment

I want to increment the phone number of stu2 by one?

The image below is the declaration.

Operations on Structures Increment
Increment

The image below is the memory after making all changes.

Operations on Structures Memory for Structure After Updation
Memory for Structure After Updation

A structure variable can be assigned to another structure variable, as shown in the image below.

Operations on Structures Assigning Structure Variable
Assigning Structure Variable

With the above assignment, the values of stu1 will be copied to stu2 as shown in the image below.

Operations on Structures Memory after structure variable assignment
Memory after structure variable assignment