T
tanvir 095438
What is the difference between structure and union?
Mahmudul hasan shovon(095411)
CEE, Islamic University of technology
Mahmudul hasan shovon(095411)
CEE, Islamic University of technology
What is the difference between structure and union?
Mahmudul hasan shovon(095411)
CEE, Islamic University of technology
What is the difference between structure and union?
Mahmudul hasan shovon(095411)
CEE, Islamic University of technology
Here is the simple example:
All the members in Union will share the same memory location.
We have a same set of members for MyStruct and MyUnion. Compiler will
allocate 16 bytes for the given structure and allocate just 4 bytes
for the union.
struct MyStruct
{
long lValue;
char ch;
char buf[4];
float f;
};
union MyUnion
{
long lValue;
char ch;
char buf[4];
float f;
};
int _tmain(int argc, _TCHAR* argv[])
{
int sz1 = sizeof(MyStruct); // will be 16 bytes
int sz2 = sizeof(MyUnion); // will be 4 bytes
}
Want to reply to this thread or ask your own question?
You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.
| Help | 1 | |
| Printf & scanf | 4 | |
| Turbo C | 1 | |
| String in Turbo C | 2 | |
| Series programme in Turbo C | 0 | |
| Turbo C | 0 | |
| C | 2 | |
| Hello | 3 |