C Structure, Union, Enums Test 1
1) What is the similarity between a structure, union and enumeration?
- All are useful in defining new data types
- All are useful in defining new variable
- All are useful in defining new structures
- 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?
- delete(var-name)
- dalloc(var-name)
- remove(var-name)
- 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.
- True
- 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?
- A
- 65
- 97
- 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.
- Yes
- No
The correct option is (b).
Explanation:
No, because the elements of union and structure are always accessed using dot(.) operator.