int a;
&a address of a
int *p capable of storing address of a non pointer
int **p capable of storing address of a pointer .this is also known as double pointer
Let us consider and code to understand above concept better
Notations for 3-D array
Do you Know ?
type specifier for printing a address--%u
&a address of a
int *p capable of storing address of a non pointer
int **p capable of storing address of a pointer .this is also known as double pointer
Let us consider and code to understand above concept better
- int *p;
- int **c;
- int a[ ]={1,2,3,4};
- *p=a; //*p gives value of a[0] i.e 1
- **c=&p; //c gives value(pointer stores address in its value) of p pointer 2293552
- //**c gives address of p pointer
- //*c --check yourself ! I don't Know
- printf("%u",p); //p gives address of a[0] 2293548
- *(a+i) is same as a[i]
- (a+i) is same as a or &a
- // in 1-d array you write int*p=a; but if a is 2-d array then this statement will give error
- int b[2][3]={ {1,2,3} , {3,4,2} }; //here b[0] occupy 8 bytes as 2 x {[0],[1],[2],[4]}=2 x 4=8
- int(*p)[3]=b; <--correct statement
- printf("%d",*b); / printf("%d",b[0]); / printf("%d",&b[0][0]); / printf("%d",b);printf("%d",&b[0]); <--means an address of first element.first row b[0][0]
- .
- printf("%d",*(*b+1)); <--means value at b[0][1] which is 2
- .
- Concluded: b[i][j]=*(b[i]+j) / *(*(b+i)+j)
- .
- .
- printf("%d",b+1);/printf("%d",*(b+1));/printf("%d",b[1]);/printf("%d",&b[1][0]);<--means
- //address of first element second row b[1][0]
- printf("%d",*(b+1)+2);. //means address of b[1][2]
Notations for 3-D array
- int c[3][2][2]={ {{2,5},{7,9}} , {{3,4},{6,1}} , {{0,8},{11,13}} };
- c[i][j][k]
- printf("%d",*c) / printf("%d",c[0]) / printf("%d",c[0][0]) <--addr of c[0][0][0]
- printf("%d",*(c[1]+1))/ / printf("%d",c[1][1])/ / printf("%d",&c[1][1][0])<--addr of c[1][1][0]
- printf("%d",*(c[0][1]+1)) <--value of c[0][1][1];
- i.e c[i][j][k]= / printf("%d",*(c[i][j]+k));/printf("%d",*(*(c[i]+j)+k));/printf("%d",*(*(*(c+i)+j)+k));
Do you Know ?
- loop pointer move by size of data type
- scanf has &a to take value
- printf has just a to print value
- in array no need to write & while passing address
type specifier for printing a address--%u
No comments:
Post a Comment