Pointer Pen questions

Source: Internet
Author: User

#include <iostream>using namespacestd;intMain () {Char*str[]={"Welcome"," to","Fortemedia","Nanjing"}; Char**p=str+1; str[0]= (*p++) +2; str[1]=* (p+1); str[2]=p[1]+3; str[3]=p[0]+ (str[2]-str[1]); cout<<str[0]<<Endl; Output ' cout '<<str[1]<<Endl; Output Nanjing cout<<str[2]<<Endl; Output Jing cout<<str[3]<<Endl; Output greturn 0;}

STR: Array of pointers, the value of STR is the address of the first element of this array, this address is stored in 0xA

Address element Address element

Str 0xA 0xA Welcome\0

Str+1 0xB 0xB to\0

Str+2 0xC 0xC Fortemedia\0

Str+3 0xD 0xD Nanjing\0

char**p=str+1;

P is first combined with *, stating that P is a pointer to the char* type

Str+1:str the address of the second element of the array, so the value that p holds is the address str+1

str[0]= (*p++) +2;

*p:p the stored address str+1 the value of this address, that is, 0xB

*p+2, which is the third character after the address, the ' 0 ' after to

P=p+1, because P points to the char*, so p=p+4, that is, p points to the address str+2, that is, the value that P holds is the address str+2

The Address element

Str 0xb+2, which is the address of

str[1]=* (p+1);

P+1, point to str+3 address, change the value of the address to store is 0xD;

Therefore, the value of * (p+1) is 0xd,cout output 0xD start to ' "" content, that is, Nanjing;

The Address element

Str+1 0xD, which is the address of N in Nanjing

str[2]=p[1]+3;

P holds a value of str+2,p[1] equivalent to * (P+1), that is, the value of str+3 address stored 0xD;

0xd+3, which is the output Nanjing characters from J to

The Address element

Str+2 0xd+3, the address of J in Nanjing

str[3]=p[0]+ (str[2]-str[1]);

STR[2]-STR[1] = 3

P[0] equivalent to *p,p stored value is str+2, so the value of *p is 0xd+3;

So str[3] = 0xd+3+3, that is, the output Nanjing the value of the beginning of the 6th bit, that is, G to ' + ';

The Address element

Str+3 0xd+6, which is the address of G in Nanjing

Pointer Pen questions

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.