Exercise: Structures Unions Enums

Questions for: Structures Unions Enums

What will be the output of the program ?
#include<stdio.h>

int main()
{
    union a
    {
        int i;
        char ch[2];
    };
    union a u;
    u.ch[0]=3;
    u.ch[1]=2;
    printf("%d, %d, %d\n", u.ch[0], u.ch[1], u.i);
    return 0;
}
A:
3, 2, 515
B:
515, 2, 3
C:
3, 2, 5
D:
515, 515, 4
Answer: A

The system will allocate 2 bytes for the union.

The statements u.ch[0]=3; u.ch[1]=2; store data in memory as given below.

What is the similarity between a structure, union and enumeration?
A:
All of them let you define new values
B:
All of them let you define new data types
C:
All of them let you define new pointers
D:
All of them let you define new structures
Answer: B
No answer description is available. Let's discuss.
How will you free the allocated memory ?
A:
remove(var-name);
B:
free(var-name);
C:
delete(var-name);
D:
dalloc(var-name);
Answer: B
No answer description is available. Let's discuss.
Ad Slot (Above Pagination)
Quiz