C Programming - Complicated Declarations - Discussion
Discussion Forum : Complicated Declarations - True / False Questions (Q.No. 1)
1.
Does the data type of all elements in the union will be same.
Discussion:
7 comments Page 1 of 1.
Nomulas said:
1 decade ago
False.
Because we can declare various data type variables according to our program convenient.
Because we can declare various data type variables according to our program convenient.
Sag said:
1 decade ago
But in union we have to declare the same data type.
Bruce said:
1 decade ago
@Sag: We don't have to declare the same datatype in union.
Here's a example from A First Book of ANSI C:
union
{
char *text;
double rate;
}uTax
Here's a example from A First Book of ANSI C:
union
{
char *text;
double rate;
}uTax
Nipa said:
1 decade ago
Union is collection of different data types which store in same address.
Aravind s unni said:
10 years ago
Pass a pointer.
Rajeshree khedkar said:
8 years ago
Yes, nice @NIPA.
Naresh said:
6 years ago
union U
{int a;
char ch;
int b;
};
In union, we can declare different/same data type.
But Memory allocates only for largest data member.
{int a;
char ch;
int b;
};
In union, we can declare different/same data type.
But Memory allocates only for largest data member.
Post your comments here:
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers