Tutorials

C Structure


C Structure Basics


Structure is a collection of data items of different data types.

It is a user defined data type which stores related information together.

It is also know as a collection of variables under a single name.

 

Defining a data structure

General format of a structure is as follows:

Struct structure_name
{
Member 1;
Member 2;
.
.
Member n;
};
  • The semicolon should be used after the closing brace brackets.
  • struct is the required keyword.
  • struct_name is the name given to the structure.

Example

struct student
{
    char name[20];
    int roll_no;
    float marks, avg;
};

Combine the variable declaration with the structures

It is defined in the following format:

Struct structure_name
{
Member 1;
Member 2;
.
.
Member n;
}variable1,variable2…variablen;

Example

struct student
{
    char name[20];
    int roll_no;
    float marks, avg;
}s1, s2, s3;

 



Please Share this page
Views : 43
Like every other website we use cookies. By using our site you acknowledge that you have read and understand our Cookie Policy, Privacy Policy, and our Terms of Service. Learn more Got it!