Two-dimensional pointer usage and two-dimensional pointer usage

Source: Internet
Author: User

Two-dimensional pointer usage and two-dimensional pointer usage

# Include <iostream>
Using namespace std;
Int main ()

{
Char * str [] = {"Welcome", "to", "Fortemedia", "Nanjing"}; // each uses ABCD to represent four elements;
Char ** p = str + 1; // p-> B;
Str [0] = (* p ++) + 2; // p-> C, str [0]-> elements after D, the content is blank;
Str [1] = * (p + 1); // p-> C, str [1]-> D;
Str [2] = p [1] + 3; // p [1]-> D, p [1] + 3 indicates that the string points to the 4th elements, that is, j;
Str [3] = p [0] + (str [2]-str [1]); // str [2]-str [1] = 3, p [0] points to the address of j, that is, g;

Cout <str [0] <endl;
Cout <str [1] <endl;
Cout <str [2] <endl;
Cout <str [3] <endl;

Return 0;
}

Result:

Null

Nanjing

Jing

G

 

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.