Structures in C Programming
In programming, structures are user-defined data types that allow combining different data types into a single type. Learn about the format, advantages, and initialization methods of structures in C. Explore how to declare variables and the rules for initializing structure members.
Download Presentation
Please find below an Image/Link to download the presentation.
The content on the website is provided AS IS for your information and personal use only. It may not be sold, licensed, or shared on other websites without obtaining consent from the author.If you encounter any issues during the download, it is possible that the publisher has removed the file from their server.
You are allowed to download the files provided on this website for personal or commercial use, subject to the condition that they are used lawfully. All files are the property of their respective owners.
The content on the website is provided AS IS for your information and personal use only. It may not be sold, licensed, or shared on other websites without obtaining consent from the author.
E N D
Presentation Transcript
Structure in C NUSRAT TASNIM LECTURER, DEPARTMENT OF SOFTWARE ENGINEERING DAFFODIL INTERNATIONAL UNIVERSITY
General Discussion Student1 Name1 Age1 ID Number1 CGPA1 Student3 Name3 Age3 ID Number3 CGPA3 Student2 Name2 Age2 ID Number2 CGPA2 ..
What is structure A structure is a user defined data type that can be used to group items of different data types into a single type. Example: struct student { char name[20]; int age; int ID Number; float CGPA; };
Advantage of structure An array can also store multiple data but only of one data type. But using structure has the advantage of storing multiple data of different data type.
Format of a structure definition Struct student { char name[40]; int age; int CGPA; Struct tag_name { data_type member1; data_type member2; data_type member3; }; };
Elements of structure definition The keyword struct The structure tag name A terminating semicolon
Structure initialization We can initialize structure in two ways- struct student { char name[40]; int age; int ID; float CGPA; }student={ Nusrat ,25,121,3.94}; struct student { char name[40]; int age; int ID; float CGPA; }; Struct student s1 ={ Nusrat ,25,121,3.94};
Rules for initializing structure We can t initialize individual members inside structure template. The order of values in braces must match the order of members in the structure definition.
Accessing structure members Structure members are accessed using dot (.) operator. Dot operator