Professional Documents
Culture Documents
ANDHRA PRADESH
Name :M.Subramanyam
Designation :Senior Lecturer
Branch :Computer Engg.
Institute :Q.Q.Govt.Polytechnic,Hyderabad.
Year/Semester :III Semester
Subject :UNIX & C
Subject Code :CM-304
Topic :Structures
Duration :50 Min
Sub Topic :Structure definition and Declaration
Teaching Aids :PPTs, Animation
CM304.76 1
Recap
1. What is an array?
CM304.76 2
Objectives
Understand structures
Define the structures
Declare the structure variables
CM304.76 3
Structure
It is heterogeneous.
Keyword
Syntax User defined word
struct tagname
{
datatype member1; Fields/attributes
datatype member2;
datatype member3;
- - - - - - - - - - - - - - - - - --------;
datatype membern;
}; End of the structure definition
CM304.76 5
Structures Contd…
CM304.76 6
Structures Contd…
CM304.76 7
Structure Example
struct emp
{
int empno;
float sal;
char gender;
};
empno, sal and gender are called members of
structure
CM304.76 8
Invalid Example
struct emp
{
int empno=10; can’t be initialized
float sal =60000.0;
char gender=‘M’;
};
Members can’t be initialised within the structure
definition.
Since memory is not allocated for the members
when the structure is defined.
CM304.76 9
Declaration of Structure Variable(s)
Once the structure is defined ,you can declare a
structure variable
Syntax:
struct tagname
structurevariable(s);
struct emp e;
empno sal gender
e
Fig 76.1
struct emp is datatype called derived datatype
CM304.76 10
Structures Contd…..
CM304.76 11
Combined Definition & Declaration
CM304.76 13
Summary
CM304.76 15
Quiz
CM304.76 16
Quiz
2) Structure definition
d) None
CM304.76 17
Quiz
2) Structure definition
d) None
CM304.76 18
Quiz
CM304.76 19
Quiz
CM304.76 20
Frequently Asked Questions
1. Define a structure.
example.
CM304.76 21