Union in C Language

O LEVEL -PAPER 3rD -- M3-R4


C  LANGUAGE


UNION IN C 



union in  c , different between structure and union
union defination



DIFFERENTIATE BETWEEN STRUCTURE AND UNION 



union in  c , different between structure and union,union in c
Different between structure and union

most important different between structure and union is that it's memory consumption in program i.e structure consume memory seperately i.e 2byte for int and 4byte for float and 1byte for char therefore total 5byte but The Union conducts only the largest bytes or data type in memory i.e in above example largest byte is float so it's used 4byte variable only and access all data type variable in 4byte at a time .



HOW TO ACCESS UNION ?


union in  c , different between structure and union
Access of union in c

EXAMPLE OF UNION IN C

union in  c , different between structure and union
Example of union in c

NOTE :- 

Remember that in the quotation given above, we can only use the one value of the one variable at a time i.e int x=5 or float y=3.5 or char z=a as we seen in above example i.e we initialize one value and print it like x=5 and again initialize y=3.5 and print it and initialize again  z='a' and print it and all variable memory will be float type  that's why it's output will be shown on screen is --

OUTPUT -

X=5

Y=3.5

Z=a

Comments

Popular posts from this blog

Important Announcements(download all my book free)

O LEVEL- INTERNET TECHNOLOGY & WEB DESIGN

Call by Reference with Pointer in C Language part-4-a