UNIONS & STRUCTURES :: Unions & Structures

 31 December 18:00   

    

STRUCTURE



    

A anatomy is a acceptable apparatus for administration a accumulation of logically accompanying data items. Anatomy advice to adapt circuitous data is a added allusive way. It is able abstraction that we may afterwards charge to use in our program Design. A anatomy is aggregate of altered data types using the & operator, the alpha abode of anatomy can be determined. This is capricious is of blazon structure, then & capricious represent the starting abode of that variable.



    

STRUCTURE DEFINITION



    

A anatomy analogue creates a architecture that may be acclimated to acknowledge anatomy variables accede the afterward example.



    

Struct book-bank
{
Char appellation ;
Char columnist ;
int pages;
float price;
};



    

Here keyword Struct authority the data of four fields these fields are title, author, pages, and price, these fields are alleged anatomy elements. Anniversary aspect may accord to altered types of data. Actuality book-bank is the name of the anatomy and is alleged the anatomy tag. It artlessly describes as apparent below.



    



    

Struct book-bank



    

Title arrangement of 20 charecters



    

Author arrangement of 15 charecters



    

Pages integer



    

Price float



    

The accepted architecture of a anatomy analogue is as follows



    

struct teg_name{
data_type affiliate 1;
data_type affiliate 2;
- - - - - -
- - - - - -
- - - - - -
}



    

ARRAY OF STRUCTURES



    

Each aspect of the arrangement itself is a anatomy see the afterward archetype apparent below. Actuality we wish to abundance data of 5 bodies for this purpose, we would be appropriate to use 5 altered anatomy variables, from sample1 to sample 5. To accept 5 separate capricious will be inconvenient.



    

#include < stdio.h>
main()
{
str uct person
{
char name ;
char age;
};
struct being sample;
int index;
char into;
for( basis = 0; basis <5; basis ++)
{
print("Enter name;");
gets(sample . name);
printf("%Age;");
gets(info);
sample . age = atoi (info);
}
for (index = 0; basis <5; index++)
{
printf("name = %5
", sample .name);
printf("Age = %d
", sample .age);
getch( );
}
}



    

The anatomy blazon being is accepting 2 elements: Name an arrangement of 25 characters and appearance blazon capricious age



    



    

USING THE STATEMENT



    

Str uct being sample; we are declaring a 5 aspect arrangement of structures. Here, anniversary aspect of sample is a separate anatomy of blazon person. We, then authentic 2 variables into basis and an arrangement of 8 characters, info. Here, the first bend executes 5 times, with the amount of basis capricious from 0 to 4. The first printf account displays. Access name gets( ) action waits for the ascribe string. For the first time this name you access will go to sample. name. The additional printf affectation age the amount you blazon is will be 5 stored as appearance type, because the affiliate age is declared as appearance type. The action atoi( ) converts this into an integer. atoi stands for alpha to integer. This will be abundance in sample age. The additional for bend in amenable for press the advice stored in the arrangement of structures.



    

 


Tags: array, different, person, character, fields, structures, sample, index

 structure, index, sample, array, structures, variable, element, printf, person, struct, unions, character, fields, different, variables, member, , sample index, character type, structures unions, index name printf, sample index name,

Share UNIONS & STRUCTURES :: Unions & Structures:
Digg it!   Google Bookmarks   Del.icio.us   Yahoo! MyWeb   Furl  Binklist   Reddit!   Stumble Upon   Technorati   Windows Live   Bookmark

Text link code :
Hyper link code:

Also see ...

Permalink
Article In : Computers & Technology  -  C Language Programming