Home > Back-end >  About the primary pointer and secondary pointer conversion
About the primary pointer and secondary pointer conversion

Time:12-08

As shown in figure don't know why just change the primary pointer to the representation of the secondary pointer is losing out

CodePudding user response:

The building Lord knows that pointer p2 represent what meaning?

CodePudding user response:

The p2 appear in the program?

CodePudding user response:

reference 1st floor SuperDay response:
I know pointer p2 represent what meaning?

The address of the p1, isn't it?

CodePudding user response:

refer to the second floor 636 f6c696e reply:
p2 appear in the program?

P2 is & amp; P1 that aren't * p2 is the value of p1 is s first address

CodePudding user response:

P1 is an array, & amp; The same value of p1 and p1

CodePudding user response:

The program how can I change it

CodePudding user response:

reference 5 floor SuperDay reply:
p1 is an array, & amp; P1 and p1 same values

What about this program I want to change how the

CodePudding user response:

I think no meaning ah, as long as master the pointer to the array and pointer array is enough, so you write pointer to an array of Pointers (that is, your so-called secondary pointer), have what special features? I am a pragmatist, as long as can realize functions, method as far as possible simple, like a, like this obscure pointer concept to people around the halo, or pointer array is more commonly used in reality a bit, and most of the cases were combined with structure

CodePudding user response:

# include & lt; stdio.h>
# include & lt; stdlib.h>
Int main (int arg c, char * argv []) {
Char s [5] [20], [20] (* (p1), * * (p2);
int i;
For (I=0; i<5; [I] i++) gets (s);
P1=s;
//p1 is a pointer to a pointer of type is char [20]
//p2 is a pointer to a pointer, corresponding to the variables of p1 address, * p2 and p1 is equivalent
The p2=& amp; P1.
Printf (" % s=p \ n ", s);
Printf (" p1=% p \ n ", (p1);
Printf (" p2=% p \ n ", p2);

For (I=0; i<5; I++) {
Printf (" p1 [% d] % p: % s \ n ", I, & amp; P1 p1 [I], [I]);
};

For (I=0; i<5; I++) {
Printf (" p2 [% d] % p: % s \ n ", 20, I * * 20 p2 + I * and * p2 + I * 20);
};

return 0;
}

CodePudding user response:

refer to the eighth floor SuperDay response:
I feel no sense, as long as master the pointer to the array and pointer array is enough, so you write pointer to an array of Pointers (that is, your so-called secondary pointer), have what special features? I am a pragmatist, as long as can realize functions, method as far as possible simple, like a, like this obscure pointer concept to people around the halo, or pointer array is more commonly used in reality, and in most cases are combined with structure of

Just freshman learn this knowledge to back on the exam must understand basic can understand other pointer can also be used on the secondary pointer
I don't know how to use the secondary stage

CodePudding user response:

9/f, the program has not understand?

CodePudding user response:

Type mismatch, the compiler should give you the hint warning,

 # include & lt; stdio.h> 


Int main (void)
{
Char s [5] [20], * p (* (p1) [20], * * (p2);
int i;

for (i=0; i <5; I++)
[I] gets (s);
P1=s;
for (i=0; i <5; I++)
Puts (* (p1 + I));
putchar('\n');

P=s [0];
The p2=& amp; P;

for (i=0; i <5; I++)
Puts (* p2 + I * 20);
return 0;
}

For your reference ~

CodePudding user response:

P1 is a pointer array, each element of the array to the content of the length of 20 bytes, so actually p1 + 1 is the displacement of the 20 bytes;
P2 is a pointer to a pointer to the size of each pointer is 4 bytes, so the p2 + 1 actually displacement of 4 bytes,

Please refer to the
"Pointer to a pointer
""Pointer array and array pointer in c + +"
"C + + array address offset
"Wish I could help you!
In addition, for the hair of my vc + + 6.0
 p2=& amp; P1. 
an error and must be written
 p2=(char * *) & amp; P1. 
?

CodePudding user response:

The
reference 11 floor SuperDay response:
9 floor of the program has not read?

A little understand but can't understand why is 20 + I * and cannot be directly + I, like * (a + I) a is an array of the first address line is 0, + I jump straight to the next line address,

CodePudding user response:

reference 12 building self-confidence boy reply:
types do not match, the compiler should give you the hint warning,

 # include & lt; stdio.h> 


Int main (void)
{
Char s [5] [20], * p (* (p1) [20], * * (p2);
int i;

for (i=0; i <5; I++)
[I] gets (s);
P1=s;
for (i=0; i <5; I++)
Puts (* (p1 + I));
putchar('\n');

P=s [0];
The p2=& amp; P;

for (i=0; i <5; I++)
Puts (* p2 + I * 20);
return 0;
}

For reference ~

Right! Tips can output the beginning why * 20 come

CodePudding user response:

On the 14th floor weixin_45788663
reference response:
Quote: reference 11 floor SuperDay response:
9 floor of the program has not read?

A little understand but can't understand why is 20 + I * and cannot be directly + I, like * (a + I) a first address is an array of row 0, + I jump straight to the next line address,

Because p1 is array pointer, associated with the length of the array, but the p2 do not have access to an array of information, only hard to add 20, but such a meaningless, it is better to use a pointer array

CodePudding user response:

reference 13 floor MianHou reply:
p1 is a pointer array, each element of the array to the content of the length of 20 bytes, so actually p1 + 1 is the displacement of the 20 bytes;
P2 is a pointer to a pointer to the size of each pointer is 4 bytes, so the p2 + 1 actually displacement of 4 bytes,

Please refer to the
"Pointer to a pointer
""Pointer array and array pointer in c + +"
"C + + array address offset
"Wish I could help you!
nullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnull
  • Related