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

Discussion

What is the output of this program?

#include <stdio.h>
struct test {
    int x;
    char y;
} test;

int main()
{
    test.x = 10;
    test.y = 'A';
    printf("%d %c", test.x,test.y);
    return 0;
}

 

  • A.10 A
  • B.garbage value garbage value
  • C.Compilation Error
  • D.None of these

Answer: A

Correct answer: 10 A

The declaration defines the structure type and a variable, both called test - legal, because tags and ordinary identifiers occupy separate namespaces. The assignments then set the members and the printf prints 10 A.

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

Post your comment

Please log in or register to post a comment.