Professional Documents
Culture Documents
Pointers: Instructor: Noor Ullah Khan
Pointers: Instructor: Noor Ullah Khan
Function can
Arrays can be
modify
modified
variables
without
without using
pointers.
pointers
Then why use pointers?
Address and
Pointers
• Address are numbers just as there are for
homes on the street.
• Starts from 0 and go on 1,2,3…….
• If you have 1MB of memory the highest
address is 1,048,575.
What is
• Whenever your program is loaded in
address? memory . It occupies a certain range of
these addresses.
• Every function/variable starts at a particular
address.
• How to find address of a variable?
• Using address of operator(&)
The address • Remember address is not same as contents
of variable.
of • << insertion operator interprets the address
Operator(&) in hexadecimal as indicated by (0X).
• Every integer variable occupies 2 bytes
exactly for (16-bit system).
• We can print out values of addresses but it’s
meaningless?
• We want variables to store these addresses.
• A variable that holds an address value is
called a pointer variable, or simply a pointer.
Pointer • What is datatype of pointer?
variable • It’s the same as the variable of whose address is
being.
• Can’t we use general pointers?
• No, compiler needs to know what, kind of
variable the pointer points to.
Accessing the variable pointed to:
Void
Either as reference or as
centimize(double&) or
pointer.
centimize(double*)