Structure in C Language

Posted on

Construction in C

Construction in C Language


Construction is a consumer outlined knowledge sort which maintain or retailer homogeneous knowledge merchandise or component in a singe variable. It’s a Mixture of primitive and derived knowledge sort.


Why Use Construction in C

In C language array can be a consumer outlined knowledge sort however array maintain or retailer solely comparable sort of knowledge, If we need to retailer different-different sort of knowledge in then we have to outlined separate variable for every sort of knowledge.

Instance: Suppose we need to retailer Scholar report, then we have to retailer….

  • Scholar Title
  • Roll quantity
  • Class
  • Handle

For retailer Scholar title and Handle we’d like character knowledge sort, for Roll quantity and sophistication we’d like integer knowledge sort.

If we’re utilizing Array then we have to outlined separate variable.


If we use Construction then we use single variable for all knowledge.


Be aware: Minimal dimension of Construction is one byte and Most dimension of Construction is sum of all members variable dimension.

Be aware: Empty Construction just isn’t doable in C Language.


Defining a Construction


At finish of the construction creation (;) have to be required as a result of it signifies that an entity is constructed.


Syntax to create construction variable

Distinction Between Array and Construction

Array Construction
1 Array is assortment of homogeneous knowledge. Construction is the gathering of heterogeneous knowledge.
2 Array knowledge are entry utilizing index. Construction components are entry utilizing . operator.
3 Array allocates static reminiscence. Buildings allocate dynamic reminiscence.
4 Array component entry takes much less time than buildings. Construction components takes extra time than Array.

Instance of Construction


Output: Enter worker Id, Title, Wage: 5 Spidy 45000 Id : 05 Title: Spidy Wage: 45000.00

Syntax to entry construction members

Through the use of following operators we will entry construction members.


When the variable is regular sort then go for struct to member operator.

When the variable is pointer sort then go for pointer to member operator.

Distinction Between Construction and Pointer in C

Construction in C check with a group of assorted knowledge sorts for instance you create a construction named “Scholar” which comprises his title , roll no, DOB an
d so on. Title is string, Roll no is int.

Whereas pointer refer to deal with in C & image are used to level some explicit place in C reminiscence.