can we initialize all the members of union?

Answers were Sorted based on User's Feedback



can we initialize all the members of union?..

Answer / banavathvishnu

union
{
int a;
char ch;
float f;
}tt = {10};
main()
{

printf("%c",tt.ch);
}

In union it is enough to initialise one variable, same
value will reflect the value in remaning members also.

Is This Answer Correct ?    5 Yes 0 No

can we initialize all the members of union?..

Answer / vadivelt

Since Union follows the memory sharing concept, it is not
possible to initialise all union varibles at a time.

ie.,

union name
{
int a;
char b;
}c = {10, 'a'};

is not possible.

But it is possible to initialise one value at a time.

ie.,

union name
{
int a;
char b;
}c = {10};

or

union name
{
int a;
char b;
}c = {'a'};

Is This Answer Correct ?    0 Yes 3 No

Post New Answer

More C Interview Questions

What are the types of arrays in c?

0 Answers  


What is difference between array and structure in c?

0 Answers  


Explain two-dimensional array.

0 Answers  


what would be the output of the following program? main() { int k = 123; char *ptr; ptr = &k; printf("%d",*ptr); }

4 Answers  


What does return 1 means in c?

0 Answers  






plssssss help !!....using array.. turbo c.. create a program that will accept number of words to be consored. .a word must not exceed 10 characters long .the text to be entered will be no longer than 200 characters .there will be no 10 words example: enter number of words to be censor: 5 enter words to censor: windows office microsoft bill gates enter text to censor: bill gates founded microsoft and makes office and windows sample output: <consored> <censored> founded <censored> and makes <censored> and <censored>

1 Answers  


what is linkage error when it occurs in c program

3 Answers  


Write a routine that prints out a 2-D array in spiral order!

1 Answers   Lucent,


process by which one bit patten in to another by bit wise operation is? (a) masking, (b) pruning, (c) biting, (d) chopping,

0 Answers   InterGraph,


What is the purpose of void in c?

0 Answers  


Explain with the aid of an example why arrays of structures don’t provide an efficient representation when it comes to adding and deleting records internal to the array.

0 Answers  


Explain what is the most efficient way to store flag values?

0 Answers  


Categories