Structures in c By Anand George
Structures Very similar to arrays. Array contains same type of elements Structures contain different type of elements. Like a wallet or bag which has many different things in it.
Use of structure Think about in the program represent on a employee of a company. Had name, id, address. Name is a string type data. Id is integer type data Address is again string. Array wont fit Has to be a structure
Initialization struct myTestStruct { int a; char b; short c; int d; }; void main() myTestStruct mts = { 1, 2, 3, 4 }; }
Example struct Student { char name[100]; int studentId; char address[300]; };
Accessing elements Dot operator
Demo Accessing structure element with dot operator.
Demo Saving the name, id, and address of 5 students and printing it out. Sort the list with name of the student and print it.
Thank you