hello guys,
i had a little problem in understand the pointer to pointer reference concept (i.e **p) how it is used. and what is the effect of uisng that.
any help will be appreciated
:)
Printable View
hello guys,
i had a little problem in understand the pointer to pointer reference concept (i.e **p) how it is used. and what is the effect of uisng that.
any help will be appreciated
:)
Try reading through this post. It was discussed decently there. Let me know if you have any questions.
Think of **p as p[][]. A multidimensional array (even though technically it's not).
Code:const char **p = {
"Apples",
"Cornbread"
};
// p[] would carry the strings
// p[][] would carry the characters of the strings
// *p would carry the strings
// **p would carry the characters of the strings
p[0][0] = 'B' // Change Apples to Bpples
**p = 'C' // Change Bpples to Cpples
Does any of that work?
I very much doubt it.
You mean because of const, or because they're string literals. Or both. ;)
Quzah.
This is crazy horse !
Code:#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main( void )
{
// Create a string array
char p[2][100];
// Copy the strings into the string array
strncpy( p[0], "Apples", sizeof( *p ) );
strncpy( p[1], "Corn Bread", sizeof( p[0] ) );
// Next is the same thing as:
// **p = 'B'
p[0][0] = 'B'; // Change Apples to Bpples
puts( p[0] );
// Next is the same thing as:
// p[1][5] = 'X'
*( ( *( p+1 ) )+5 ) = 'X'; // Change Corn Bread to Corn Xread
puts( p[1] );
return 0;
}