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

Sir i need notes for structure,functions,pointers in c language can you help me please

0 Answers   TCS,


Is a pointer a kind of array?

0 Answers  


how many header file is in C language ?

44 Answers   College School Exams Tests, CTS, IBM, IMS, Infosys, ME, Sign Solutions, Wipro, XVT,


Concat two string with most overlapped substring has to removeĀ  "abcd"+ "cdef" = "abcdef

6 Answers  


advantages of pointers?

3 Answers  






WRITE A PROGRAM IN C TO MULTIPLY TWO 2-D ARRAYS

4 Answers  


write an interactive C program that will encode or decode a line of text.To encode a line of text,proceed as follows. 1.convert each character,including blank spaces,to its ASCII equivalent. 2.Generate a positive random integer.add this integer to the ASCII equivalent of each character.The same random integer will be used for the entire line of text. 3.Suppose that N1 represents the lowest permissible value in the ASCII code,and N2 represents the highest permissible value.If the number obtained in step 2 above(i.e.,the original ASCII equivalent plus the random integer)exceeds N2,then subtract the largest possible multiple of N2 from this number,and add the remainder to N1.Hence the encoded number will always fall between N1 and N2,and will therefore always represent some ASCII character. 4.Dislay the characters that correspond to the encoded ASCII values.  The procedure is reversed when decoding a line of text.Be certain,however,that the same random number is used in decodingas was used in encoding.

0 Answers  


Is there any possibility to create customized header file with c programming language?

0 Answers  


i want to know aptitude questions,technical questions

2 Answers  


Explain main function in c?

0 Answers  


What is table lookup in c?

0 Answers  


Explain how can I write functions that take a variable number of arguments?

0 Answers  


Categories