Home > Back-end >  On the secondary pointer doubts
On the secondary pointer doubts

Time:10-28

As shown in figure is the secondary pointer explain the int type figure, this also can understand
Don't understand the character of the secondary pointer
Char this
For example,
Can get char * a="hello"
And char * a [2]={" hello ", "good"}
Said the two cases under
Their corresponding secondary pointer, when to take to the words, when the picked is a single letter?

CodePudding user response:


Char * when a pointer to the first address string, a [I] of the ith a position when a letter (I start from 0)
Char * a [2] is the pointer array contains two elements, a [0] to first address the first string, and a first address [1] points to the second string,

CodePudding user response:

The diagram above, change int to char is the same, there is no difference between
Char * a="hello"; System in the read only memory allocated block address length is 6, content is hello5 characters, plus the 0 at the end of a string of characters, a total of six characters
And then given a pointer to the address, you can be as an array of ways one by one to visit these characters, can also use it as a whole string
But you can't change any content of this string, try to rewrite it will bug even collapsed
"Hello" is actually a const char * type, const keyword said content cannot be changed

Char * a [2]={" ABC ", "123"};
A is an array, the array element type is char *, you can't put a simple understanding of become a char * *
As simply as profound understanding of the array and pointer; Array name can be a pointer to use, but is inequitable to pointer
Array is defined, it has been clear about the data, the size of the array name is simply the first address of the data, the address is a pointer; But the data area is an array,
Back to the definition of the char * a [2], a [0], [1] is a char * type, respectively to the initialization time to set the two strings;

Char * * is defined as the right
Char * a="ABC";
Char * * pa=& amp; a;
Pa is a address, that is, the address of a char * type variable, this is the accurate definition of char * *, and here the int * * is exactly the same as

Char * in front of a [2]={... }
A is actually a char (*) [2], is a pointer to an array, and no pointer to char *, this is accurately
This definition can be treat as a char * * to use, but is not really a char * * type

Like a natural number is an integer, but is not the integer is a natural number



CodePudding user response:

Comes down to you, you still not understand the difference between Pointers and arrays

Reading carefully, part of an array, there will be introduced

Language books views, unlike other books, you want to throw out the book example code, the rest of the words, one by one to read slowly taste
Code is used to explain the text, the core is on the text description
Look at those words like math word problems, don't go to words, are easy to fall into the pit

CodePudding user response:

The first is a not a subset of the second?
The first to take a letter a [0], a [1], etc.
The second to a letter a [0] [0], a [0] [1]

CodePudding user response:

reference 1st floor wxf54318 response:
char * when a pointer to the first address string, a [I] of the ith a position when a letter (I start from 0)
Char * a [2] is the pointer array contains two elements, a [0] to first address the first string, and a first address [1] points to the second string,


The second way to get letters, see sample with * can take the words?

CodePudding user response:

Fun
reference 3 floor response:
comes down to you, you still not understand the difference between Pointers and arrays

Reading carefully, part of an array, there will be introduced

Language books views, unlike other books, you want to throw out the book example code, the rest of the words, one by one to read slowly taste
Code is used to explain the text, the core is on the text description
Look at those words like math word problems, don't go to words, are easy to fall into a variety of pit


The second way to get letters, see sample with * can take the words?

CodePudding user response:

* (a + 1) [I]
* (* (a + 1) + (I)

CodePudding user response:

Know the type of the pointer, the corresponding plus * and offset or use subscript can

CodePudding user response:

Fun
reference 7 floor response:
* (a + 1) [I]
* (* (a + 1) + (I)


What are the two results, please? Is a meaning?
Char * a [2]={" hello ", "good"}

* of [1] is a good (pointer array, each element is a pointer, [1] refers to a good address, plus * is good? ]
So * (a + 1) [I] what is that? A + 1 is stem what?

CodePudding user response:

A blind man lighting a candle
You don't watch in front of me to reply you, is a problem on your reply
Really don't understand, you write a line of code
Int I=2;
Printf (" % c % c ", * (a + 1) [I], * (* (a + 1) + (I));
What you see output

On a question you ask, is there a way to get to the letters, give you the two is to take a letter
  • Related