- All are useful in defining new variable
- All are useful in defining new structures
- All are useful in defining new pointers
Explanation:
A structure, enumeration, and union can all be beneficial when defining new data types in the C programming language.
It is employed to generate fresh data types that encompass various data types such as integers, characters, floats, and arrays within a user-defined data type. This allows users to incorporate new values and operational logic in a straightforward 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)
Explanation:
The predefined function free(var-name) is employed to release or deallocate memory space. When we utilize free, the associated memory address can be made available for future use or other tasks.
Hence, the free(var-name) function is utilized to deallocate memory in a C program.
3) A union can be nested in a structure.
- True
- False
Explanation:
In the process of mapping or assigning addresses to structures, the program utilizes a union as a single data type within it.
Hence, it is accurate to state that a union can be nested within a structure statement.
4) What will be the output of the below program?
#include<stdio.h>
main()
{
union abc {
int a;
char cha;
}var;
var.cha = 'A';
printf("%d", var.a);
}
- Garbage value
Explanation:
The union variable shares a single memory location for all its elements, where 'a' is assigned the value 'A' with an ASCII value of 65.
Printing the value 65 in the output can be achieved with the statement printf("%d", var.a);.
Therefore the output of the program is 65.
5) The elements of union and structure are always accessed using & operator.
Explanation:
No, as the components of union and structure are consistently accessed with the dot (.) operator.