This is a discussion on Make out of Structure and Union within the C and C++ Programming forums, part of the Software Development category; Hi all, Can anyone explain me about make out of Structure and Union in C....
| |||||||
| Register | FAQ | Members List | Calendar | Mark Forums Read |
| |||
| Hi all, Can anyone explain me about make out of Structure and Union in C.
__________________ Regards, VELHARI I am not totally useless. I can be used for a bad example |
| Sponsored Links |
| |||
| Hi, Let me explain u about Structure and Union Structure ======= Structure is a collection of elements having different datatypes For eg.. Struct a { int b[5]; //->Memory allocated(10) char c;//->Memory allocated(1) }; Structure ends with semicolon... Here the declaration tells that 'a'->Structure Variable b[5]->b is a structure element that can hold 5-elements of same datatype[int]..(i.e., it can store 5-Integer Element) c->character element.. For b[5]->10-bytes are allocated,c->'1-byte is allocated. Totally for structure variable 'a'->11-bytes are allocated.. For each element separate memory is allocated.. But in Union, Union c { int b; char c; }; Here it takes the variable of largest datatype and assign that single memory for all union elements.. i.e.,For union variable 'c' it allocates the total of 2-bytes both for element 'b' and 'c'.(i.e.,Refer same Memory location ,No individual memory for each variable) This is the main difference between Union and Structure. |
| |||
| hi velhari, Structure is a collection of memory block, of different data type, in which it will have separate memory space for each data type. Structure Definition Quote:
UNion Definition Quote:
__________________ SeeSamJagan- Sky is not the "LIMIT", Death is not the END, There is still something beyond.... |
![]() |
| Thread Tools | |
| Display Modes | |
| |
Similar Threads | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Union and Union All | itbarota | Database Support | 2 | 03-03-2008 12:41 AM |
| UNION ALL faster than a UNION? | vadivelanvaidyanathan | Database Support | 4 | 08-18-2007 01:04 AM |
| what is the UNION in c++? with Example | sundarraja | C and C++ Programming | 1 | 07-20-2007 06:44 AM |
| ence between “C structure” and “C++ structure”. ? | Arun | C and C++ Programming | 1 | 07-18-2007 07:30 AM |
| What's the difference between a structure and a union | prasath | C and C++ Programming | 1 | 07-18-2007 04:14 AM |