C Programming - Structures, Unions, Enums - Discussion
Discussion Forum : Structures, Unions, Enums - Point Out Errors (Q.No. 8)
8.
Point out the error in the program?
#include<stdio.h>
int main()
{
union a
{
int i;
char ch[2];
};
union a z1 = {512};
union a z2 = {0, 2};
return 0;
}
Discussion:
21 comments Page 2 of 3.
Uma said:
1 decade ago
In unions we can initialize only one member at the declaring of object/variable for the union.
Swati said:
1 decade ago
When I execute this program it show.
No errors or program output.
But option provides right answer Error: in Initializing z2.
Which is best answer in both two?
No errors or program output.
But option provides right answer Error: in Initializing z2.
Which is best answer in both two?
Siddharth mishra said:
1 decade ago
Union denotes singularity hence only one value at a time is permitted for the init. Hence the answer.
Sugi said:
1 decade ago
Can anyone explain the concepts of pointer structure and union clearly?
Sudha said:
1 decade ago
Union allocates at only once time for memory allocation at the same type of union and overwrite allocate in one value.
Bnr said:
9 years ago
All of you read this here. Union is not a problem, in this union has two members one is 'int' and another is 'char' all of you may know how to initialize character must be placed in between two double quotes hear z2 character initialization is error correct is '2' this.
(1)
Stnj said:
9 years ago
@Bnr.
You are correct. Thank you.
You are correct. Thank you.
Ing said:
8 years ago
#include<stdio.h>
int main()
{
union a
{
int i;
char ch[2];
};
union a z1 = {512};
union a z2[2] = {5,6};
return 0;
}
int main()
{
union a
{
int i;
char ch[2];
};
union a z1 = {512};
union a z2[2] = {5,6};
return 0;
}
Sexy said:
7 years ago
Program compiles normally but issues a warning of trying to assign more than one value at a time for a union.
(1)
MAYRA said:
5 years ago
I am not understanding this.
Post your comments here:
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers