✔ C-LANGUAGE CHAPTERS:-
1. C-Introduction
2. C-Constants
3. C-Basic Programs
4. C-Instructors
5. C-Operators
6. C-If Else Statement
7. C-Loop Contructs
8. C-Nesting Of Loops
9. C-Programming Examples
10. C-Functions
11. C-Functions Naming Convention
12. C-Pointers
13. C-Arrays
14. C-Arrays & Functions
15. C-Strings
16. C-Structures
17. C-Union
18. C-Storage Classes
19. C-PreProcessor
20. C-Header Files
21. C-R/W one Line
22. C-Accessing Random File
23. C-Important Point
24. C-Interview Questions
1. C-Introduction
2. C-Constants
3. C-Basic Programs
4. C-Instructors
5. C-Operators
6. C-If Else Statement
7. C-Loop Contructs
8. C-Nesting Of Loops
9. C-Programming Examples
10. C-Functions
11. C-Functions Naming Convention
12. C-Pointers
13. C-Arrays
14. C-Arrays & Functions
15. C-Strings
16. C-Structures
17. C-Union
18. C-Storage Classes
19. C-PreProcessor
20. C-Header Files
21. C-R/W one Line
22. C-Accessing Random File
23. C-Important Point
24. C-Interview Questions
It is also user defined data type, which is used to store collection of variables having a different data type. Structure and Union are totally similar to one another expect that Union`s members share same memory.
Syntax: union
{
----------------------;
----------------------;
----------------------;
};
Two basic applications for Union in c programming are: -
- Utilize the same memory location in many different ways.
- To create flexible structure.
“Union holds a one data type value at time in memory and that value is equal to larger storage of their members.”
Eg: union student
{
int rollno;
char name[20];
};
Memory will store by union in 20 bytes i.e. of ‘name’ data member.
Members of union can be accessed by using ( . ) dot operator, and initialization and declaration of union variable is same as in structure.
Eg: #include
Eg: #include
void main( )
{
union student
{
int rollno;
char name[20];
float fee;
};
union student std;
std.rollno = 101;
std.name = “Kareena”;
std.fee = 10,000;
printf(“\n The roll number is : ”,std.rollno);
printf(“\n The Name is : ”,std.name);
printf(“\n The Fees is : ”,std.fee);
}
Difference between Structure and Union: -
Structure | Union |
All the data members share separate memory. | Members of union data type share same memory. |
‘struct’ keyword is used to declare the structure. | ‘union’ keyword is used to declare the Union. |
It occupies large space in memory. | It occupies less space in memory. |
Enumerated data type [enum]: -
C provides some built in data types like int, float apart from that C also provides facility to define your own data type called “enumerated”. It is purely for numeric and used to give integer constant values to means. It defines special data items in form of numeric constants and gives ordered series to variable [data members].
Eg: Suppose we have 12 months, we can assign the integer constants to each and every month sequentially. So we don`t need to write the name of month rather integer constants can be used at their place. ‘enum’ keyword is used.
Syntax: enum
Syntax: enum
{
Member list;
};
Eg: enum week
{
Monday, Tuesday, Wednesday, Friday;
};
Declaration of variables in C programming: -
Eg: week w;
In the previous example the ‘Monday’ is equivalent to 0, and ‘Tuesday’ is 1 and so on.
We can declare more than one variable of same enum type.
Eg: week w, e;
Eg: week w, e;
This both variables when compared will give the result euqal.
Eg: w = Monday;
Eg: w = Monday;
e = Tuesday;
if(w == e)
printf(“Both are Equal”);
When we write any of the defined enumeration (Sunday, Monday, Tuesday) with printf( ) statement they will print integer constant, so the format specifier is %d.
Eg: void main( )
Eg: void main( )
{
printf(“%d”, Tuesday); 1
printf(“%d”, Thursday); 4