Top

Discussion

What will be the output of the following code −

#include 
#include 
int main() {
   union my_union {
      int i;
      float f;
      char c;
   };
   union my_union* u;
   u = (union my_union*)malloc(sizeof(union my_union));
   u->f = 20.60f;
   prin

 

  • A.Garbage Value
  • B.20.600000
  • C.Syntax Error
  • D.20.6

Answer: B

Using unions, we can use same memory location to hold multiple type of data. All member of union uses same memory location which has maximum space. Here float is used, which has 20.60f = 20.600000. 

No comment is present. Be the first to comment.
Loading…

Post your comment