Some understanding of C language Level two pointers

Source: Internet
Author: User

Recently re-learning "C and pointers", an example in the pointer that chapter-looking for a specific character in a string of strings: Version 2 has a sentence to see not quite understand, * (*string) + +, so write the program test, pondering a bit.

Test the program like this:

#include <stdio.h>int main () {char str1[] = "ABCD"; char str2[] = "EFGH"; char *pstrarray[2] = {str1, str2};char **ps TR1 = Pstrarray;char **pstr2 = Pstrarray;    (*PSTR1) ++;*pstr2++;p rintf ("%c", **PSTR1);p rintf ("%c", **PSTR2); GetChar ();}

VS compile run, final print effect: B E

The second good understanding, the first result but suddenly do not understand, then the thinking of the misunderstanding is this:

After execution (*PSTR1) + + only *pstr1 changed, PSTR1 itself did not change, guess **pstr1 output should be a.

Now figured out, pStr1 really did not change, pStr1 inside is pstrarray[0] address, and Pstrarray[0] saved is str1[0] address, when (*PSTR1) + + is executed, that is equivalent to pstrarray[0]++, At this point pstrarray[0] points to str1[1], so the output of **PSTR1 is B.

The reason to enter the mistaken thinking is that *str1 equivalent to &pstrarray[0] is not obvious, thought is just a temporary variable, not saved is discarded, there is the suspicion of execution after pStr1 whether or not have been changed.

Some understanding of C language Level two pointers

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.