Originally Posted by
mutandis
But, would you only use **ptr when dereferencing?
I ask because I *think* I've seen it used as an argument in a function prototype (do you guys call them prototypes or declarations here?)
I've confused myself with these double asterisks myself... Could anyone give an example of when you would want a pointer to a pointer? Why wouldn't you just change where the first pointer pointed to?
-Dave
Code:
// this might be a bit 'old style' C
main( int argv, char **argc) {
.....etc....
eg programname parameter1 parameter2 etc....eg print file1 file2 etc...
argv is the number of parameters to a program
**argc are the parameters, a pointer to an array of strings, or expressed in another
way a pointer to a pointer to a character.
Code:
in print file1 file2
argc[0]="file1"
argc[0][1]='i'
argc[0][4]='1'
argc[1]="file2"
argc[1][0]='f'
argc[1][4]='2'
char words[2][6];
ptr=words;
strcpy(*ptr,"word1");
ptr++;
strcpy(*ptr,"word2");
If you printed
printf("%s\n",words[0]);
printf("%s\n",words[1]);
it would probably say
word1
word2
or
ptr=words;
printf("%s\n",*ptr);
ptr++
printf("%s\n",*ptr);
Should do the same.
Then again it might fall over