C Programming + Tutorials in C for Beginners

C Structures

Home  »  C Programming  »  C Structures

     As you know different type of variables can be used for different purpose having different types of data-types. C supports such types of a constructed data type, which is called Structure. In Structure you can pack number of variables having different data type with single structure, which is called structure name or tag name or structure tag.


Definition :

     A structure is heterogeneous collection of related fields. Here fields are called structure member or structure element. Every field has different type-specifier (data-type).

The definition of structure of opposite of array, because array is set of homogeneous elements. But the structure has deep relationship with array.

Structure Variables : The general syntax used to declare a structure and structure variables is written as below :
struct structure-tag
  date-type1 strcture element-1 or member-1;
  date-type2 strcture element-2 or member-2;
  date-type3 strcture element-3 or member-3;
  date-type n strcture element-n or member-n;
  struct structure-tag v1,v2,..........vn;
  local declaration;
  executable statements;

Simple Structure Program :

Output is as :


Note:- struct is the keyword which we can't use as a variable.

Structure within Structure (Nested Structure):

Output is as :
Enter the Name and City

Structure and array :

     Arrays play very important role with structure. Structure has two types of view with the array. The two types of relationship of structure with array...

<< Previous Topic
Next Topic >>

Next Post »
Thanks for your comment