Some Understanding of level 2 pointers in C language, C language pointers
Recently I have re-learned "C and pointer", an example in the pointer chapter-finding a specific character in a string: Version 2 is not clear, * (* string) ++, so I tested the program and figured it out.
The test procedure is as follows:
# Include <stdio. h> int main () {char str1 [] = "ABCD"; char str2 [] = "EFGH"; char * pStrArray [2] = {str1, str2 }; char ** pStr1 = pStrArray; char ** pStr2 = pStrArray; (* pStr1) ++; * pStr2 ++; printf ("% c", ** pStr1 ); printf ("% c", ** pStr2); getchar ();}
VS compile and run, the final print effect: B E
Second, I had a good understanding, but I couldn't understand the first result. The misunderstanding was as follows:
After the execution (* pStr1) ++ is executed, only * pStr1 is changed, and pStr1 itself is not changed. Assume that the output of ** pStr1 is.
Now, pStr1 has not been changed. pStr1 stores the address of pStrArray [0], while pStrArray [0] stores the address of str1 [0, when (* pStr1) ++ is executed, it is equivalent to pStrArray [0] ++. In this case, pStrArray [0] points to str1 [1], therefore, ** pStr1 outputs B.
The reason for misunderstanding is that * Str1 is equivalent to & pStrArray [0]. It is not obvious that it is only a temporary variable and is discarded if it is not saved, another issue is whether pStr1 has been changed after execution.