Introduction to
Structure Types
Ms. Mamoona Tasadduq
:
Slides: CS Deptt. Sharif University of Technology
Edited By: Dr. M. Aksam Iftikhar, CUI Lahore
, Input and Output – Lecture 4
Lecture Outline
• Background
• Introduction to struct types
– Data members of struct
• Define struct types
– Version 1, 2 and 3
• Declare/Initialize struct variables
– Access data members of struct variables
• Structures as New Data Type
– Using operators with struct variables
– Arrays of struct variables.
– Nested struct variables
2
, Input and Output – Lecture 4
Introduction
⮚ Our variables until now
⮚ Single variable
int i, char c, float f
⮚ Set of same type elements: Array
int a[10], char c[20]
⮚ If data are not same type, but related?
⮚ Example: Information about students
⮚ Student Name
⮚ Student Family Name
⮚ Student Number
⮚ Student Grade
3
, Input and Output – Lecture 4
Introduction
⮚How to save the student information?
⮚1- Use separated variables
⮚ char st_name[20];
⮚ char st_fam_name[20]
;
⮚ int id;
⮚ int grade;
⮚2- Put them altogether, they are related
⮚Use struct
4