C Programming - Structures, Unions, Enums - Discussion
Discussion Forum : Structures, Unions, Enums - True / False Questions (Q.No. 1)
1.
A union cannot be nested in a structure
Discussion:
7 comments Page 1 of 1.
Praphulla said:
1 decade ago
@Ramesh your answer is right or not I don't no but I have little bit doubt. How can we use union within structure?
Can @Ramesh explain it? "with relevant to memory concept" because structure allocates diff memory location for diff data types & union allocates only one largest memory location & share it for all other so I'm waiting your answer.
Can @Ramesh explain it? "with relevant to memory concept" because structure allocates diff memory location for diff data types & union allocates only one largest memory location & share it for all other so I'm waiting your answer.
Ashutosh said:
1 decade ago
Thanks ramesh.
Ramesh said:
1 decade ago
A union can be nested in structure, because in address mapping or allocation of structure , it takes union as a one datatype in it..
Ex:
#include<stdio.h>
int main()
{
struct s
{
int a;
union u
{
char c;
} u1;
}s1;
s1.u1.c='m';
s1.a= 10;
printf("%d\t%c",s1.a,s1.u1.c);
}
Output: 10 m
Ex:
#include<stdio.h>
int main()
{
struct s
{
int a;
union u
{
char c;
} u1;
}s1;
s1.u1.c='m';
s1.a= 10;
printf("%d\t%c",s1.a,s1.u1.c);
}
Output: 10 m
Sowjanya said:
1 decade ago
Give an example please?
V.L.NARASIMHARAO said:
1 decade ago
Please give me any one explanation.
Jhansi said:
1 decade ago
Give the explanation please.
Inderpal Singh said:
1 decade ago
How? give an example.
Post your comments here:
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers