Structure in C Langauge

Raiyan Shahid
2 min readJun 14, 2021

--

Structure in C Language

Structure in C is a collection if more than one variable which may be same type or different type.

To declare a structure we use a keyword structure:

The genral format is:

struct structureName

{

Datatype var1;

Datatype var2;

}

  • The declaration of structure is treated as a single statement, hence it must be terminated by semicolon.
  • Structure create an user define data type of its own type.
  • The declaration of structure is only a blue print or template.
  • There is no any memory allocation for the member of structure.
  • To use the feature of structure we have to create a structure variable
  • To create a structure variable we use structure name as a data type.

The general format :

struct strcyName,var1,var2 ;

  • As soon as structure variable is created, sufficient memory will be allocated for a structure variable.
  • The amount of memory for structure variable will be depend on the member of structure.
  • Every structure variable gets a separate memory allocation according to its member which is not overlapped by each other.
  • To access the member of structure to the structure variable we use dot operator.
  • Basically structure variable is useful to store complex number.

Characteristics of Structure

Initialization of stucture.

We can initialize the structure in the following manner:

struct first

{

int a;

float b;

};

void main()

{

struct first f1={10,15.50};

struct first f2 = {20,25.50};

printf(“%d%f”,f1.a,f1.b);

printf(“%d%f,f1.a,f1.b);

}

We can also declare a structure variable directly at the time of structure declaration.

Refer : ArzaTechs

--

--