Structure In C Language 0 2091

Introduction To Structure

Arrays are the preferred method of storing objects of the same data type. In addition to array three more derived data types that can be used to store information: structure, unions, bit fields, typedef and enumerator. Unlike array these can be used to store the data of same or different type.

Structure

A Structure can be defined data type which can represent several different types of data in a single unit. Each individual data item within the structure is referred to as member.

A Structure is the method of packing the data of different types to organize the data in a more meaningful way.

A structure definition creates a format that may be used to declare structure variable.

A Structure definition is specified by using the keyword struct. This is followed by braces enclosing the members and their data types.

Example Of Structure

struct student /*definition of structure*/
{
int roll; /*members*/
char name [10 ];
float per;
}s1 ,s2; /*objects or variables of the structure student*/

The members of the structure are not variables and so on memory is allocated to them.

They are allowed space in the memory only when the objects are declared. (e.g. s1 and s2).

The keyword struct declares a structure student which holds three different details namely roll, name, marks.

These fields are called members or elements of a structure. This structure is named as student, the name is called as structure tag.

Variable/Object declaration In Structure

struct student s1, s2;

The variables of the structure can be declared along with the definition as

struct student
{
int roll;
char name[50];
float marks;
}s1 ,s2;

Points to be noted about structure

1. The structure definition ends with a semicolon.

2. While the entire definition is considered as a statement, each member is declared independently for its name and type in a separate statement inside the definition (also called as template).

3. The tag name can be declared with the structure definition or even later in the main function.

4. The memory is allocated to the variables and not to the members of a structure.

Video About Structure In C

 

Previous ArticleNext Article
Indian Mirchi will serve you taste in Indian news, general knowledge and information. Hope you like the story I write here and expect your points of discussion to improve them and give the best chili test out of the story. I will write tutorials also that helps students. In case you are looking for any specific information then share me in the comment.

Send this to a friend