You are on page 1of 16

DEPARTMENT OF TECHNICAL EDUCATION

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 :Functions and structures
Teaching Aids :PPTs,Animation
CM304.79 1
Recap

 How to find the size of the structure?


 What is nested structure?
 How to access members using pointer to
structure?

CM304.79 2
Objectives

On completion of this period, you would be able to know …


 Passing members of structure variables separately to a
function.
 Passing an entire structure to a function.
 Passing pointer to structure as a argument to a function.
 Return structure from a function.

CM304.79 3
Structures and Functions

 Structures can be passed to a function in 3 ways

 Passing structure elements to a function.

 Passing entire structure to a function.

 Passing address of the structure to a function.

CM304.79 4
Passing Structure Elements to Function

 Any ordinary variables can be passed to a


function.
 Members of a structure variable can also be
passed to a function.

CM304.79 5
Example

CM304.79 6
Passing an Entire Structure to a Function

 We can pass int, float, char etc., variables to a


function as its arguments.
 A structure variable can also be passed to a
function as its argument.

CM304.79 7
Example

CM304.79 8
Passing Pointer to Structure

 Starting addresses of variables can be passed to

a function.

 Starting address of the structure variable can

also be passed to a function.

 Structure can be manipulated using pointer.

CM304.79 9
Example

CM304.79 10
Returning structure from a function

 A function can return int, float, char etc.,

 Similarly a function can also return structure.

CM304.79 11
Ex:

Return
type

CM304.79 12
Summary

In this class, you have learnt about…


 Passing structure members as function
arguments.
 Passing structures as function arguments.
 Passing address of the structure as function
argument.
 Function returns structure.

CM304.79 13
Quiz

 Structures are passed to functions only by


pass by reference method.
true/ fals
e

CM304.79 14
Quiz

 Structures are passed to functions only by


pass by reference method.
true/ fals
e

CM304.79 15
Frequently Asked Questions

1. Explain the method of passing structures as


arguments to function.

3. Write a program to define structure with


tagname state with fields statename, no.of
districts and total population. Read and display
the data by passing the address of the
structure to user defined function.

CM304.79 16

You might also like