Skip to main content

Posts

Showing posts from July, 2013

Structures in C

Structure is user defined data type which is used to store heterogeneous data under unique name. Keyword ' struct ' is used to declare structure. We already know that arrays are many variables of the same type grouped together under the same name. Similarity with arrays Structures are like arrays except that they allow many variables of different types grouped together under the same name. For example you can create a structure called person which is made up of a string for the name and an integer for the age. Here is how you would create that person structure in struct  person { char   * name ; int  age ; }; The above is just a declaration of a type. You must still create a variable of that type to be able to use it. Here is how you create a variable called p of the type person: Code: #include <stdio.h> struct  person { char   * name ; int  age ; }; int  main () { struct  person p ; ...