Share this post on:

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.

Share this post on:
Avatar Raiyan

Author: Raiyan

Hi, I guess you're here because you want to know a bit about me. huh? I am not so good on talking about myself but I'll give a short about me.

My Name is Raiyan. I am a Professional Application Developer and a Blogger.
I started this website to Share my Knowledge. Here I provide all my knowledge whatever I earned till now.

One Comment

  1. Pingback: What is Union in C Programming - ArzaTechs

Leave a Comment

Your email address will not be published. Required fields are marked *