Javatpoint Logo
Javatpoint Logo

C Structure, Union, Enums Test 3


11) What is a size of the following union definition?

  1. 4
  2. 8
  3. 2
  4. 1

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?

  1. 4 4 garbage value
  2. 4 4 0
  3. 4 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?

  1. Yes
  2. No

The correct option is (b).

Explanation:

A compiler may leave the holes in structure by padding in the first char in a structure with another byte for ensuring that the integer is stored at a location.

Also, there is 2 extra bytes after the integer to ensure that long integer is stored at specified address which is multiple of 4.

Therefore the structure does not always occupy 7 bytes.


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

  1. enum
  2. character
  3. integer
  4. float

The correct option is (d).

Explanation:

In C-language switch/casev statement is defined by the language specification to use an int value therefore we cannot use a float value in switch/case statement.


15) In C language nested unions are allowed.

  1. True
  2. False

The correct option is (a).

Explanation:

True, C language allows the use of nested union. Therefore we can use the union inside a union in C program.






Youtube For Videos Join Our Youtube Channel: Join Now

Feedback


Help Others, Please Share

facebook twitter pinterest

Learn Latest Tutorials


Preparation


Trending Technologies


B.Tech / MCA