This is a discussion on What's the difference between a structure and a union within the C and C++ Programming forums, part of the Software Development category; Hi, can anyone tell,What's the difference between a structure and a union? Thanks, Prasath.K...
| |||||||
| Register | FAQ | Members List | Calendar | Mark Forums Read |
| |||
| Hi prasath i guess this reply will fullfill ur query "While structure enables us treat a number of different variables stored at different in memory , a union enables us to treat the same space in memory as a number of different variables. That is a Union offers a way for a section of memory to be treated as a variable of one type on one occasion and as a different variable of a different type on another occasion. Union allocates the memory equal to the maximum memory required by the member of the union but structure allocates the memory equal to the total memory required by the members. Union allocates the memory equal to the maximum memory required by the member of the union but structure allocates the memory equal to the total memory required by the members. Example: union exforsys_t { char c; int i; float f; } exforsys; Defines three elements: exforsys.c exforsys.i exforsys.f Each one with a different data type. Since all of them are referring to the same location in memory, the modification of one of the elements will affect the value of all of them. We cannot store different values in them independent from each other." |
![]() |
| Thread Tools | |
| Display Modes | |
| |
Similar Threads | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Make out of Structure and Union | velhari | C and C++ Programming | 2 | 04-03-2008 03:55 AM |
| UNION ALL faster than a UNION? | vadivelanvaidyanathan | Database Support | 4 | 08-18-2007 02:04 AM |
| Difference between "C structure" and "C++ structure". | Sabari | C and C++ Programming | 2 | 08-09-2007 08:41 AM |
| What is the difference between UNION and UNIONALL in SQL Server? | bluesky | Database Support | 1 | 07-25-2007 05:53 AM |
| Difference between "C structure" and "C++ structure". | vigneshgets | C and C++ Programming | 1 | 07-17-2007 01:11 AM |