Page 18 - PROGRAMMING IN C_Neat
P. 18
10. Explain union with an example. *
Union:
Union is like a structure but all its members share the same memory area.
The size of a union variable is the size of its largest member.
General Form:
union union_name
{
datatype1 member1;
datatype2 member2;
_
_
_
datatype n member n;
};
union union_name variable_name;
Example:
union student
{
int rollno;
char name[20];
float percentage;
};
union student s;
The members of the union can be accessed as follows:
s.rollno
s.name
s.percentage
The largest member of the union is name (20 characters). Its size is 20 bytes. Therefore, the size of the
union variable, s is 20 bytes.
_______________________________________________________________________________________
11. Explain the important functions available in <math.h> header file. OR Explain the math
functions. *
Math Functions:
Mathematical functions are stored in the math.h header file.
1. sin():
Used to find the sin value of its argument.
General Form:
double sin(double a);
Example:
double x = sin(3.14/2); Output:
x = 1 (approx.)
2. cos():
Used to find the cos value of its argument.