A structure is a user-defined data type. You have the ability to define a new type of data considerably more complex than the types we have been using. A structure is a collection of one or more variables, possibly of different types, grouped together under a single name for convenient handling. Structures are called “records” in some languages, notably Pascal. Structures help organise complicated data, particularly in large programs, because they permit a group of related variables to be treated as a unit instead of as separate entities. The best way to understand a structure is to look at an example


#include “stdio.h”

void main( )


struct {

char initial; /* last name initial */

int age; /* childs age */

int grade; /* childs grade in school */

} boy, girl;

boy.initial = ‘R’;

boy.age = 15;

boy.grade = 75;

girl.age = boy.age – 1; /* she is one year younger */

girl.grade = 82;

girl.initial = ‘H’;

printf(“%c is %d years old and got a grade of %d\n”,

girl.initial, girl.age, girl.grade);

printf(“%c is %d years old and got a grade of %d\n”,

boy.initial, boy.age, boy.grade);


The program begins with a structure definition. The key word struct is followed by some simple variables between the braces, which are the components of the structure. After the closing brace, you will find two variables listed, namely boy, and girl. According to the definition of a structure, boy is now a variable composed of three elements: initial, age, and grade. Each of the three fields are associated with boy, and each can store a variable of its respective type. The variable girl is also a variable containing three fields with the same names as those of boy but are actually different variables. We have therefore defined 6 simple variables.





About Dinesh

I am engineering student........ I am selected in Microsoft Student Partner as MSP............

Posted on September 9, 2011, in C#, C++, Knowledge. Bookmark the permalink. Leave a comment.

Leave a Reply

Please log in using one of these methods to post your comment: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: