Monday, April 11, 2016

Structure & Declaration of a structure

Structure :


Structure is the most important user defined data type in C. A structure is a collection of variables under a single name. These variables can be of different types, and each has a name which is used to select it from the structure. But in an array, all the data items are of same type. The individual variables in a structure are called member variables. A structure is a convenient way of grouping several pieces of related information together.

Declaration of a structure

Here's the most used example of structure for a student information like the following example:


  1. struct student
  2. {
  3.           char name[25];
  4.           char faculty_Name[20];
  5.           int age;
  6.           int reg;
  7. };

We can also declare an another variable for struct.
Like

struct student StudentDetail;


Declaration of a structure always begins with the key word struct followed by a user given name, here the student.


So, we can use different types data and also store them in an array in the structure. And finally, full item will works as a unit which we can use afterwards.


No comments:

Post a Comment