Array, pointer experience exchange (heap, stack discussion ......)

Source: Internet
Author: User

Once in the future) 11:02:42
Is 2*4 + 3 + 1
(Once in the future) 11:03:00
I wrote an error in the previous offset derivation. We should add one more pair.
(There is no snow in heaven) 11:03:22
No.
(Once in the future) 11:03:34
Cold, I am also a little confused, huh, huh
(Once in the future) 11:03:43
No. The first one is zero. Hahaha
(There is no snow in heaven) 11:03:52

(Once in the future) 11:03:56
If I add one more, I don't need to add
Man. Ash) 11:03:57
I feel that the addressing method of a [2] [3] should be:
First look for a [2], that is, skip the positions of two int [3,
Then, skip the three int positions at the current position and you will find them.
In this way, the array and pointer are in harmony.
(There is no snow in heaven) 11:04:03
It's warm. I just finished class.
(Once in the future) 11:04:05
Right
(Once in the future) 11:04:11
Ash is correct.
(There is no snow in heaven) 11:04:26
Like
(Beginner c) 11:04:32
Another cool man arrived
(There is no snow in heaven) 11:05:39

(Man. Ash) 11:05:46

(Beginner c) 11:07:06
Why are they all sweaty?
(Beginner c) 11:07:37
(11:03:57) man.ash (26367948)
I feel that the addressing method of a [2] [3] should be:
First look for a [2], that is, skip the positions of two int [3,
Then, skip the three int positions at the current position and you will find them.
In this way, the array and pointer are in harmony.
---------------------------
How to implement it?
(Once in the future) 11:08:36
Implementation? Implementation is what I wrote
(Beginner c) 11:10:21
Confused ~~~~ Come back...
(Man. Ash) 11:10:26
Int A [2] [3], that is
INT (* A) [3]
Is to define a pointer A, the pointer to the type is an array with a length of 3 int
In this case, if addressing:
A [1] [2]
Is * (a [1] + 2)
* (A + 1) + 2)
That is to say, jump 1 from
(Beginner c) 11:12:00
Jump 1 from
----------------
Wood understandable
(Man. Ash) 11:12:26
The distance of this hop is of the type, because the type is an int array with a length of 3, so jump 1*3 * sizeof (INT)
However, the * (a + 1) type is also a pointer of the int type. Therefore, the * (a + 1) + 2 result is the unit in which the pointer jumps two integers forward.
Man. Ash) 11:14:03
Int *;
A + = 1;
That is, the distance between A and the int width of the jump.
If a points to an array of the int type instead of an int type, the number of elements in the array is three,
A + = 1
Do you just jump forward to the distance of an array?
(Beginner c) 11:14:29
Solved ....
(Once in the future) 11:14:33
First, you need to understand that the pointer is divided into two parts: the pointer address and the pointer data. For a pointer P, the P operation is to move it to the address location, * P operations are performed on the data it points.
(There is no snow in heaven) 11:15:12
You speak much better than the teacher,
(Beginner c) 11:15:25
INT (* P) [3]
P ++;
Int [3]
(Once in the future) 11:15:28
Oh, my teacher spoke much better than me.
(Man. Ash) 11:15:43
A [2] = * (a + 2)
The formula Ricky gave yesterday is really classic.
(Once in the future) 11:15:56
And the 0 [p]
(Once in the future) 11:15:59
Too strong
(Man. Ash) 11:16:21
Points out the internal relationship between the pointer and the array.
(Beginner c) 11:16:21
0 [p] I cannot understand it now
(Man. Ash) 11:17:04
Prove that the addition switching law is used:
A [2] = * (a + 2) = * (2 + a) = 2 [A]
(Once in the future) 11:17:05
0 [p] is to move from the starting point of the program memory to the position of the P pointer
(Ricky) 11:17:42
(Man. Ash) 11:17:04
Prove that the addition switching law is used:
A [2] = * (a + 2) = * (2 + a) = 2 [A]. That's the truth,
(Beginner c) 11:17:56
Can this be done?
(Ricky) 11:18:10
In the same way, 2 can be changed to 0, or even a negative number, which can be larger than the array size.
(Beginner c) 11:18:15
Gong Jing
(There is no snow in heaven) 11:18:22
It was the first time I heard that it was still possible.
(Once in the future) 11:18:23
Well, C will survive forever
(Ricky) 11:18:24
As long as the size is still in the stack
(There is no snow in heaven) 11:18:33

(Man. Ash) 11:18:41
C is so broad and profound.
(Ricky) 11:18:41
This will not cause errors.
(There is no snow in heaven) 11:18:54
Learning ing
(Once in the future) 11:19:00
After understanding this, you will understand that the entire computer is operating resources with pointers in the C compiler.
(Ricky) 11:19:10
This is why sometimes the pointer crosses the border to get the wrong result, but sometimes the program crashes.
(Beginner c) 11:20:04
2 [a] What is this time?
------------------------
I don't know.
(There is no snow in heaven) 11:20:31
A [2] is the same
(Ricky) 11:20:35
2 [a] is equal to a [2 ].
(Ricky) 11:21:01
Actually, it is deceiving the compiler. The compilation code obtained is the same.
(There is no snow in heaven) 11:21:14
That is to say, it is something of the same memory block.
(Beginner c) 11:22:52
..........
(Once in the future) 11:23:21
In fact, I don't think it can be called deception. In a mathematical sense, such a conversion is perfect.
(Once in the future) 11:23:36
This computation is complete in mathematics.
11:23:41 (Meteor Shower)

(Man. Ash) 11:23:46
When processing a [2], the C compiler regards A and 2 as the same thing? It's just a simple address addition. It doesn't matter who is there.
I don't know. Do you understand this?
(Once in the future) 11:24:16
A [2] is offset from a 2, 2 [a] is offset from 2 A, they should have been consistent
(Once in the future) 11:24:29
Ash is right.
(Beginner c) 11:24:43
A [2] is offset from a 2, 2 [a] is offset from 2 A, they should have been consistent
--------------------
This statement is good.
(Ricky) 11:24:45
Makes sense.
(Go all the way) 00:51:39

11:24:55 (Meteor Shower)
A [2] is offset from a 2, 2 [a] is offset from 2

Never seen
(There is no snow in heaven) 11:25:25
It is the same place.
(Go all the way) 00:52:24
I knew I should check the corresponding assembly code.
11:25:38 (Meteor Shower)
Oh,

The message you sent just now: "I knew you should check the corresponding assembly code" was not sent successfully (the server timed out ).

(Beginner c) 11:25:58
Now, I think the best explanation is the future. Although Ricky puts forward this concept, it is ash.
11:26:40 (Meteor Shower)
Haha,
(Once in the future) 11:26:42
(Ricky) 11:17:42
(Man. Ash) 11:17:04
Prove that the addition switching law is used:
A [2] = * (a + 2) = * (2 + a) = 2 [A]. That's the truth,

Ash's proof is the most rigorous
(Beginner c) 11:26:59
But cannot understand
(Guderian★11:27:40
Report something else

(Man. Ash) 11:27:45
Let's say it's the 18 th palm of the dragon
Dance looks good
(Once in the future) 11:28:02
You learned functional analysis from the last year.
(Beginner c) 11:28:33
Functional Analysis?
I have learned it ~~~
 
(Ulica) 11:29:53
Which of the following systems will be embedded?
(Beginner c) 11:30:24
Int A [10]
Is this character a variable?
A = A [-1] ???
11:30:42 (Meteor Shower)
A is a constant address.

(Man. Ash) 11:31:02
A is the address
(Man. Ash) 11:31:18
Is the pointer
11:31:19 (Meteor Shower)
Yes
(Beginner c) 11:31:20
A [0]?

11:31:47 (Meteor Shower)
A [0] indicates an element.
(Beginner c) 11:31:57
& A [0]?
11:32:10 (Meteor Shower)
Haha,
(Man. Ash) 11:32:16
Int A [10]
Equivalent
Int * A = new [10];
A is equivalent to & A [0]
(Man. Ash) 11:32:42
Of course, one is on the stack and the other is on the stack.

11:32:42 (Meteor Shower)
Master
(Beginner c) 11:33:18
Stack and stack? Ask ash to talk... I don't understand yet?
(Man. Ash) 11:34:02
Everything except New is created on the stack.
(Beginner c) 11:34:37
Stack I remember is first-in-first-out, right?
(Ulica) 11:34:48
FIFO,
(Ricky) 11:35:05
That is the stack data structure, and this is not a concept
(Once in the future) 11:35:19
The stack and stack here are not the stacks in the Data Structure
(Once in the future) 11:35:24
Memory Management
(Beginner c) 11:35:25
So I don't understand it ~~~~
(Beginner c) 11:35:35
Let's talk about ....
(Man. Ash) 11:35:39
FIFO? Queue?
(Ulica) 11:35:41
Queue is advanced
Stack is post-import, first-release
(Ulica) 11:35:49
Well,
(Beginner c) 11:35:59
Wrong
(Beginner c) 11:36:15
But let's talk about the system stack and stack first?
(Beginner c) 11:36:23
Don't understand ~~~~
(Beginner c) 11:36:52
Is there an operating system in the book? If yes, go back and try again.
11:37:09 (Meteor Shower)
Let's take a look at the data structure,
(Man. Ash) 11:37:14
I only know the general operation mode, but I am not quite clear about the specific organization mode. The expert gave a profound lecture.
No books in the operating system, at least none of the textbooks I have ever seen
(Beginner c) 11:37:29
I don't think so...
(Man. Ash) 11:37:32
It is actually related to the compilation principle.
(Ricky) 11:37:34
Compilation principles

(Past and future

To put it simply, stack resources are compiled and managed by programmers themselves.
(The data structure heap and stack are another problem)

(Once in the future) 11:39:45
I can't tell you more details.
(CD-ROM) 11:39:47
Are there any differences between teams and stacks?
(Ulica) 11:39:57
A little bit,
(Man. Ash) 11:39:58
{
Int;
{
Int B;
}
Int C;
}
Stack entry method:
C
B --------- scope of brackets
A
(Once in the future) 11:40:09
The resources applied for on the stack need to be released by the programmer, not on the stack
(CD-ROM) 11:40:32
Understand
(There is no snow in heaven) 11:42:06
The data structure is based on your own defined method.
(Beginner c) 11:42:10
Now let's talk about the stack in the running program instead of the stack in the data structure.
(Man. Ash) 11:42:18
Adding or deleting a stack is easy. For example, if you want to add or delete another int d to a new program;
So, as long as you move the top of the stack up one cell, the space will come out.
It is easier to delete it. For example, if the outer parenthesis scope exists, you only need to move the pointer down to A, and everything is cleared.
That's why int A [10];
Than int * A = new [10];
The reason for the high speed
(There is no snow in heaven) 11:42:19
It should not be the same as in the system
(Man. Ash) 11:43:30
The stack principle is relatively simple. I know the basic concepts of the stack, but I don't know how to implement it during operations. The compilation principle we teach does not involve dynamic memory allocation.

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.