void main(){
char a[2][30]={"Don't walk in front of me..", "I am not follow"};
printf("%c%c", *(a[0]+9), *(*(a+0)+5));
}
And the output of the program is
k
Some example based explanations...
c-arrays can be accessed in two ways:
As an array:
char a[10] = "0123456789";
printf("%c", a[5]); // prints "5"
As a pointer:
char a[10] = "0123456789";
printf("%c", *(a + 5)); // prints "5"
In the second example we are just dereferencing a
as a pointer to the start of the string plus 5.
This can be used for 2d, 3d, etc... arrays as well:
char a[2][10] = {"012", "abc"};
printf("%c", *(*(a + 0)+1)); // prints "1"
printf("%c", *(*(a + 1)+1)); // prints "b"
You can mix the two methods:
printf("%c", *(a[0] + 1); // prints "1"
printf("%c", *(a + 1)[1]; // prints "b"
And just for completeness (this could be considered the "normal" way to access the array values):
printf("%c", a[0][1]; // prints "1"
printf("%c", a[1][1]; // prints "b"
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments