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 :Initialization,accessing &assignment
Teaching Aids :PPTs,Animation
CM304.77 1
Recap
Define a structure?
Explain structure definition with an example?
How to declare a structure variable?
Is the memory allocated for the members
when the structure is defined?
Can you assign values to members within the
structure?
How to combine structure definition and
structure variable declaration ?
CM304.77 2
Objectives
CM304.77 3
Initialization
Members can be initialized at the time of defining
the structure or declaration of structure variable
Syntax :
struct tagname variable={value1,value2,…valuen};
Example
Method 1) struct emp e={1000,60000.50,’M’};
CM304.77 4
Initialization Contd…..
Method 3) struct emp
{
int empno;
float sal;
char gender;
}e={1000,60000.50,’M’};
initialized during
difinition
empno sal
gender
1000 60000.50 M
e
struct emp e;
e={101,5000.5,’M’};
Members should be initialized at the time of
declaration.
CM304.77 6
Accessing Structure Members
Dot(.) operator is used to access members
Syntax:
Structurevariable.membername;
Example
CM304.77 8
Structure Assignment
e.empno=5001;
e.sal=1000;
e.gender=‘M’;
CM304.77 9
Assigning One Structure Variable to
Another
Contents of one structure variable can be
copied to another variable.
Example
struct sample
{
char a;
int b;
float c;
};
struct sample s1,s2;
CM304.77 10
Assigning One Structure Variable to
Another
s1.a=‘A’;
s1.b=100; Contd…
s1.c=100.5;
a b c
s1 A 100 100.5
Fig 77.2
s2=s1;
a b c
s2 A 100 100.5
Fig 77.3
CM304.77 11
Example
CM304.77 12
Reading data for the members
CM304.77 13
Ex:
Example
CM304.77 14
Summary
CM304.77 15
Quiz
CM304.77 16
Quiz
CM304.77 17
Quiz
a)*(star)
b) &(ampersand)
c) .(dot)
d) [](brackest)
CM304.77 18
Quiz
a)*(star)
b) &(ampersand)
c) .(dot)
d) [](brackest)
CM304.77 19
Frequently Asked Questions
CM304.77 20