Machine-translated by Google. Questions are authored in English.
Top

Discussion

What is the output of this program?

#include <stdio.h>
int main()
{
    union demo {
        int x;
        int y;
    };
 
    union demo a = 100;
    printf("%d %d",a.x,a.y);
}

 

  • A.100 0
  • B.100 100
  • C.0 0
  • D.Compilation Error

Answer: D

Correct answer: Compilation Error

A union cannot be initialised from a bare value: union demo a = 100; is rejected, because the compiler must be told which member is meant. union demo a = {100}; would initialise the first member, and {.y = 100} would name it explicitly.

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

Post your comment

Please log in or register to post a comment.