Pointer
Pointer
Pointer
contd.
P is said to point xyz variable.
Value vs Location
Size of Basic Data type
sizeof(int) = 2
sizeof(float) = 4
sizeof(double) = 8
Sample Program
Address Operation
Pointer Arithmetic
Pointer Arithmatic Example -1
char
a[]={‘1’,’2’,’3’,’4’,’5’}
char *p;
p=a; /1000
P++ //1001
p++//1002
1 2 3 4 5
Int *p;
p = x;
p &x[0] 1000 *p 1
p+1 &x[1] 1002 *(p+1) 2
p+2 &x[2] 1004 *(p+2) 3
p+3 &x[3] 1006 *(p+3) 4
p+4 &x[4] 1008 *(p+4) 5
Address of x[3] = base address +(3 X scale factor of int)
= 1000 +(3 X 2)
= 1006
Function returning pointer
Void main int* fun(int a,int b)
{ int a=10,b=20; {
int *x; int c;
x=fun(a,b); // fun(10,20) c=a+b;
*x++; return &c; // return 30;
print(x) }
}