Defining a Structure

Defining a Structure

Defining a Structure is a process of creating the skeleton of physical object that can be understood by compiler .It consists of Structure name and the description of it’s member(property).

Definition of a structure creates a template are format that describes the characteristics of it’s member .

The general syntax of a structure definition is:
Struct structurename{
               Datatype member1;
               Datatype member2;
               …………………………………..
               Datatype membern; 
                        };
Here struct is a keyword , which tells the compiler that a structure is being defined . member1 , member2 ,………,membern are the member of structure and are declared inside curly bracket .
There should be a semicolon at the end of the curly braces

These member can be of any data type like int , char , float , array , pointer or another structure

Structurename is the name of the structure and is used further in the program to declare Structure variables of this types

Definition of a structure provides and more data type that can be used in program

It is important to note that definition of structure does not reserve any space in memory for the members.Although the syntax of the declaration of member inside the definition of Structure is identical to the syntax we use in declaring variables but they are not variables . They do not have any existence until they are attached with a structure variables.

The member name should be different inside the structure definition but it can be same outside the Structure definition and inside other Structure definition.

Let us take an example of defining the Structure :

e.g:
struct man{
           char name[21];
           int rollno;
           float salary;
                };
Here man is the Structure name and there are three member i.e name, rollno , salary
.
Structure can be defined globally or locally




You can Browse related article below for more information and program code related to Structure  Does above is helpful , Post you views in comment

DO NOT MISS OTHER C PROGRAMMING TUTORIAL

* indicates required


Defining a Structure


Comments

Popular posts from this blog

Print pattern in c - explore new perspectives in pattern printing

Copy Constructor

C Programming Quiz online on input and output