Introduction to Structure

EmbLogic RCD Labs
2 min readMay 12, 2020

Structure is a user-defined datatype in C language which allows us to combine data of different types together. Structure helps to Construct a complex data type which is more meaningful. It is somewhat similar to an Array, but an array holds data of similar type only. But structure on the other hand, can store data of any type, which is practical more useful.

For example:- If I have to write a program to store Student information, which will have Student’s name, age, branch, permanent address, father’s name etc, which included string values, integer values etc, how can I use arrays for this problem, I will require something which can holds data of different types together.

In structure, data is stored in form of records.

Struct syntax:-

struct name

{

structure -element 1;

structure -element 2;

};

As you can see in the syntax above, we start with the struct keyword, and name is user defined data type, then inside the curly braces, we have to mention all the member variables, which are nothing but normal c language variables of different types like int, float,array etc.

After the closing curly braces, we can specify one or more structure variables, again this is optional.

Note:- The closing curly braces in the structure type declaration must be followed by a semicolon(;).

Example of Structure:-

struct student

{

char name[25];

int age;

char branch[10];

char gender;

};

Here struct student declares a structure to holds the details of a student which consists of 4 data fields, namely name, age, branch and gender. These fields are called structure elements or members.

Each member can have different datatype, like in the case, name is an array of char type and age is of int type etc. student is the name of the structure and is called as the structure user defined data type.

--

--

EmbLogic RCD Labs
0 Followers

EmbLogicTM is a technology design house and professional training company, providing research, competency development and customised training solutions.