Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
ANDHRA PRADESH
Name : Murali Krishna Chintala
Designation : Lecturer in CME
Branch : Computer Engineering
Institute : SUVR & SR GPW, Ethamukkala
Year/Semester : III Semester
Subject : UNIX & C
Subject Code : CM – 304
Topic : Basics of Pointers
Duration : 50 Min
Sub Topic : Pointers to functions
Teaching Aids : PPT, Animations
CM304.74 1
Objective
CM304.74 2
Pointers to functions
return-type (*ptr)();
CM304.74 4
Pointers to functions
Example:
int (*ptr)(int);
CM304.74 5
Pointers to functions
Example:
int fun(int);
int (*ptr)(int);
ptr=&fun;
CM304.74 6
Example
#include<stdio.h>
float fun(float);
main()
{
float x,value;
scanf(%f”,&x);
value=(*fun)(x); /* function is called through
pointer */
printf(“%f”,value);
}
CM304.74 7
Example
Contd..
float fun(float y)
{
return(y*y);
}
CM304.74 8
Dynamic memory management functions
CM304.74 9
Dynamic memory management functions
Contd..
Example:
CM304.74 10
Dynamic memory management functions
Contd..
CM304.74 11
Dynamic memory management functions
Contd..
CM304.74 12
Dynamic memory management functions
Contd..
Uses of dynamic memory allocation
Optimizes the usage of storage space.
Used to allocate additional storage space or
to release the unwanted memory space at run
time.
Extremely useful when dealing with list of
structures, as it allows the list to expand as
new records are added and contract as
records are deleted.
CM304.74 13
Summary
In this class, we have learnt about..
Pointer to a function contains the address of the
function in memory.
Under dynamic allocation scheme, storage is
allocated to a program and released back to the
computer while the program is running, rather
than fixed at compile time.
CM304.74 14
Quiz
1. Pointer to the function contains the address
of the function in memory.
a) True
b) False
c) None
CM304.74 15
Quiz
1. Pointer to the function contains the address
of the function in memory.
a) True
b) False
c) None
CM304.74 16
Quiz
a) True
b) False
c) None
CM304.74 17
Quiz
a) True
b) False
c) None
CM304.74 18
Assignment
CM304.74 19
Frequently Asked Questions
CM304.74 20