What is the difference b/w Structure & Union?

Answer Posted / nakul sharma

Memory allocated for any structure is equal to the sum of
memory required by each structure member.

Example: In a structure 'abc' below, memory allocated will
be 7 Bytes (2 Bytes for int a + 1 Byte for char b + 4 Bytes
for float c ina 32 bit processor)
struct abc
{
int a;
char b;
float c;
}

But in union memory allocated for it is equal to the memory
required by the biggest (in terms of memory it use) union
member.

Example: In a union 'abc' below, memory allocated will be 4
Bytes as float c is the biggest union member here and it
uses 4 Bytes of memory in 32 bit processor.

union abc
{
int a;
char b;
float c;
}

Is This Answer Correct ?    19 Yes 1 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

what is a constant pointer in C

680


What is use of bit field?

774


What type of function is main ()?

588


Is main a keyword in c?

632


What is nested structure?

574






struct screen_pos{ int row, col } ;move_right(cursor)struct screen_pos *cursor;{ cursor.col++; } /* This statementhas a syntax error */What is the correct statement a) cursor.col = cursor.col + 1; b) col.cursor++; c) *cursor.col++; d) pointer

766


What is the c value paradox and how is it explained?

575


When was c language developed?

703


What is structure pointer in c?

573


What are the benefits of organizational structure?

574


What is unary operator?

660


What is const volatile variable in c?

578


how to capitalise first letter of each word in a given string?

1434


Explain what are reserved words?

635


Compare and contrast compilers from interpreters.

684