what is the output of this C code
output:
66 B
4
Explanation:
union temp t={66,'A'};
this statement will initialize only the first member of the union x with 66 and the compiler will ignore the second value 'A', as one element is sufficient to initialize all union members as they share the same memory locations
sizeof(t) =4 size of largest element in memory location
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
union temp | |
{ | |
int a; | |
char c; | |
}; | |
int main() | |
{ | |
union temp t={66,'A'};// initialize the union members | |
printf("%d\t%c\n",t.a,t.c); | |
printf("%d\n",sizeof(t)); | |
return 0; | |
} |
66 B
4
Explanation:
union temp t={66,'A'};
this statement will initialize only the first member of the union x with 66 and the compiler will ignore the second value 'A', as one element is sufficient to initialize all union members as they share the same memory locations
sizeof(t) =4 size of largest element in memory location
No comments:
Post a Comment