Struct Copy & Comparison

Copy structure means copying all variables of a structure to another structure. Structure comparison means comparing all variables of a structure to another structure. Structure Copy We can copy the structure variable directly using ‘=’ sign, only if both source and destination variables are of the same structure. Means both structure variables must be variables…

Allocation of Memory

Structure storage in memory The members of a structure are stored consecutively in the memory. The size of members may differ from one machine to machine. But the important point to note about member storages is, they are stored consecutively in memory. Example program to understand structure member storage In the below example, there is…

Return Structure through functions

“Returning structure through function” statement has 2 meanings: Returning structure variable through function, Returning structure member through function. We are going to understand both one by one. Returning structure variable through function Syntax of returning structure variable through function is as listed below for function declaration, call, and definition.  Function declaration struct  <structure name>  <function…

Passing Struct through functions

“Passing structure through function” statement has 2 meanings: Passing structure variable through function, passing structure member through function. We are going to understand both one by one. Passing structure variable through function In this, we pass the variable of structure as an argument of a function. Syntax of the same is listed below for function…

Unions

Whatever we studied about the structure and whatever is explained after this topic about structure is the same for union. We can use union, wherever we are using structure but there are some differences between union and structure and those are explained below. Below differences we have to keep in mind while making a program…

Array of Struct

If we want many variables of the same structure then we can make an array of structure variables. Because it is time consuming to make many variables of the same structure. Let us understand this by an example. In the below example, structure str has 3 variables: stu1, stu2. stu3, struct str{ int roll_no; float…

Nested Struct

Structure within a structure is called nested structure. There are two methods for declaring structure within a structure. Those are listed below. Normally the main structure is called the outer structure and the nested structure is called the inner structure. Method 1 Declaring inner structure outside outer structure and declaring a variable of inner structure…

Usage of Struct

To declare a structure first we have to write the keyword “struct”. Then we have to write a user-defined name of the structure. After that, members of the structure are declared in curly braces. The end of the structure is shown by the semicolon “;”. The members are nothing but just declaring simple variables with…

Structure in C

As the array is used to make variables of the same data type and can be accessed by the same name but different index. The structure is used to make variables which have different variables of different data types (which are called structure members). Let us understand by an example. Ex1 is showing an array…

Register

We can understand all storage classes by differentiating all of those according to their default value, keyword, storage, scope, life. Which are listed in the table below. Storage Class Keyword Default Value Storage Scope Life Automatic auto Garbage RAM Limited to block in which it is declared Till execution of block in which it is…