Professional Documents
Culture Documents
Lec09 Structure
Lec09 Structure
Department of IT Engineering
C Programming
Exercise
TA Contact:
Name: Mr. Kheang Kim Ang
Email: kimangkheang@gmail.com
Phone 086 348378
Room: 311
2
Content
Structures
Declaration of Structure
In contrast, array is homogeneous since it can contain only data of the same type
Examples:
A structure type is usually defined at the beginning of a program just after the main()
statement
Structure tag is optional Structure tag or identifier
Keyword struct use for
declaring structure in c
struct struct_identifier{
datatype identifier_list; Each identifier
datatype identifier_list; defines a member
of the structure.
----------
----------
};
Lectured by: Kor Sokchea 6
Declaration of Structures
Example
struct Student{ struct Date{
int id; int day;
char name[30]; int month;
char gender; int year;
int age; };
float score The “Date” structure has
}; 3 members, day, month,
year
The “Student” structure has 5
members, id, name, gender, age,
score
struct circle{
int x;
int y;
float radius;
};
With structure identifier, it can defines new structure variable
struct-identifier.member;
uint x, y;
In the above example, a new type unsigned integer as uint have defined
Then, uint can be used in program as any native data type, and declare other
variables with its data type.
Example:
Line line;
0 1 2 … 98 99
An array of structs: Multiple types of data in each array element
0 1 2 … 98 99
21