Professional Documents
Culture Documents
Lecture 14-2
Lecture 14-2
Advanced Programming
Shahanshah Abbas
shani@grel.ist.edu.pk
Advanced-Programming 1
Outline:
• Pointers
• Pointer with arrays
• Pointer withFunction
Pointers
• What are pointers:
• Computer memory consist of address
• For every Byte there is an address For This we Use Pointers
• Address like numbers 10,29,2299 etc.
• So when Code/ Program runs
• Occupies a specific range of the memory address
• Likewise every variable and function starts from a particular memory address
• Why we use pointers.
• Accessing Array elements
• Obtaining memory from system
• Passing arrays and strings to function
• Passing arguments to a function
• Producing data structures such a linked lists etc..
When Program Run
Pointers
• Address-of operator Address occupation in memory
Address of operator
Addresses in hexadecimal
Pointers
But the int variable occupies 4 bytes in memory so what this address is showing
Must be assigned a
variable address value
Values stored in PointerVariable
• Sometimes we need to access a variable value which is pointed by
pointer
• Let’s see.
Dereference operator or
indirection operator or
content of operator
Values stored in PointerVariable
• So far we have print the assigned variable addresses and values using
pointers.
• Pointers can also be used to perform any task just as we do on
variable directly like to assign a variable value