C Structure 3

union xyz {

char x,y,z,a,b,c,d,e;

int i;

}xyz;

main

{

printf( "%d", sizeof( xyz ));

}

Example


The correct option is (a).

Explanation:

Union is special data type used in C programming it allows to store different data types in the same memory location.

All the element of union share the common memory and union size is biggest element size.

Therefore the output of the program or size of union definition is 4.

## 12) What will be the output of the below program?

include<stdio.h>

main

{

struct { int y;} var = {4}, *a = &var;

printf("%d %d %d",var.y,a->y,(*a).y);

}

Example


- 4 4 garbage value

- 4 4 0

- 4 4 4

- Compile error

The correct option is (c).

Explanation:

The two possible methods of accessing structure elements using pointer is by using * or -> (arrow operator).

Therefore the output of a program is 4 4 4

## 13) If an integer is 2 bytes wide, a character is 1 byte wide and a long integer is 4 bytes wide then will the following structure always occupy 7 bytes?

struct employ

{

int j;

char ch;

long int a;

};

Example


The correct option is (b).

Explanation:

A compiler might fill structural gaps by inserting extra bytes before the first character in a structure to align an integer at a specific memory location.

Additionally, there are 2 additional bytes following the integer to guarantee that the long integer is stored at a designated address that is a multiple of 4.

Thus, the arrangement may not consistently require 7 bytes of space.

## 14) Which data type cannot be checked in switch-case statement?

- enum

- character

- integer

- float

The correct option is (d).

Explanation:

In the C programming language, the switch/case statement is mandated by the language specification to operate with an integer value, hence it is not possible to utilize a floating-point value in a switch/case statement.

## 15) In C language nested unions are allowed.

- True

- False

The correct option is (a).

Explanation:

Indeed, in C programming language, nested unions are supported, enabling the utilization of one union within another union.

Input Required

This code uses input(). Please provide values below: