Javatpoint Logo
Javatpoint Logo

C Structure, Union, Enums Test 1


1) What is the similarity between a structure, union and enumeration?

  1. All are useful in defining new data types
  2. All are useful in defining new variable
  3. All are useful in defining new structures
  4. All are useful in defining new pointers

The correct option is (a).

Explanation:

A structure, enumeration and union all of them can be helpful in defining a new data types in C language.

It is used for creating new data types that holds all kinds of data type like int, char, float, array inside a user defined data type. So user can use new values and logic of operation in simple manner.

2) How will we free the allocated memory in a C program?

  1. delete(var-name)
  2. dalloc(var-name)
  3. remove(var-name)
  4. free(var-name)

The correct option is (d).

Explanation:

The built in function free(var-name) is used for free or clear the memory space. If we use free() the referred memory location can be released for the future use or other operations.

Therefore the free(var-name) is used for clear the allocated memory in a C program.

3) A union can be nested in a structure.

  1. True
  2. False

The correct option is (a).

Explanation:

In address mapping or allocation of structure, the program takes union as a one data type in it.

Therefore union can be nested in a structure statement is true.

4) What will be the output of the below program?

  1. A
  2. 65
  3. 97
  4. Garbage value

The correct option is (b).

Explanation:

The union variable share the common memory for all its elements 'a' gets 'A' whose ASCII value is 65.

The statement printf("%d", var.a); is used for printing the value 65 in output.

Therefore the output of the program is 65.

5) The elements of union and structure are always accessed using & operator.

  1. Yes
  2. No

The correct option is (b).

Explanation:

No, because the elements of union and structure are always accessed using dot(.) operator.





Please Share

facebook twitter google plus pinterest

Learn Latest Tutorials


B.Tech / MCA