How to Declare Structures in C
A structure declaration specifies the grouping of variables
of different types in a single unit. It simply acts as a template or blueprint
that may be used to create structure variables.
The general syntax for declaring a structure in C is:
The declaration starts with
the structure header that consists of keyword struct followed by a tag that serves as the structure name. It can
be used for creating structure variables. The individual members of the
structure are declared and enclosed in curly ({}) braces. The semicolon placed
at the end of closing brace marks the end of structure declaration.
For Example:
struct student
{
int
rollno ;
char
name [20];
float
marks ;
};
The above declaration
declares a structure student. It
consist of three members rollno, name and
marks of type int, char [ ], and float respectively.
The above declaration doesn't define any variable i.e. it doesn't set aside any
space in memory. It is merely a specification that represents information about
structure. It tells how a structure will look like when it is defined.
Post a Comment