Professional Documents
Culture Documents
Algorithm
BESE-2A/B
Lecture 02
Aasma Zahid
Outline
• Pointer to variable
• Pointers and Copy Constructors
• Function call by value
• Function call by reference
• Pointer to Function
• Pointer to UDTs
• Null Pointer
– Points to nothing
– Language specific value
• Usually zero
second = numPtr;
• Comparison (==)
– if(second == numPtr) returns true
– Both points to same pointee
• Bad Pointers
– Uninitialized
– Dereferencing bad pointer
• Lucky: if you get runtime error
• Unlucky: if it corrupts random area of memory leading to malfunctioned
program execution later
9/13/2012 DSA - Fall 2012 - SEECS, NUST 5
Example
void PointerTest() {
int a = 1;
int b = 2;
int c = 3;
int* p;
int* q;
strcpy(node2.name, “Wendy”);
node2.age = 30;
name = strdup(n.name);
age = n.age;
}
return * this;
}
9/13/2012 DSA - Fall 2012 - SEECS, NUST 11
FUNCTION CALL BY VALUE AND BY
REFERENCE
• Multi-dimensional array
p1 = &c1;
p2 = &c2;
*p1= * p2;
p1 = p2;
(*p1).real;
p1->real;
9/13/2012 DSA - Fall 2012 - SEECS, NUST 25
Questions?