Use the stack to implement the four operations in C .

Updated on technology 2024-03-22
9 answers
  1. Anonymous users2024-02-07

    It doesn't seem to be very easy! I'll make it up again!

  2. Anonymous users2024-02-06

    1. Stack: It is automatically allocated and released by the compiler, storing the parameter values of functions, local variables, etc. Local variables, task thread functions, and the like are placed in the (used) stack, and the stack utilization is higher.

    It behaves like a stack in a data structure. In particular, stacks belong to threads, and each thread will have its own stack.

    2. Heap: It is generally allocated by the programmer to release, if the programmer does not release it, it may cause memory leakage. Note that it is different from the heap in the data structure, and the allocation method is similar to the linked list, the common thing is that the malloc out belongs to the heap area, just like the fixed area, which is released when it is free, which is a bit similar to the global and static.

  3. Anonymous users2024-02-05

    The stack is automatically allocated by the system, and the heap is the memory dynamically requested by the programmer himself, for example, you int i; i is stored in the stack memory, such as char *p=(char*)malloc(sizeof(char)); The memory that p points to is stored in the heap memory.

    Hope it helps.

  4. Anonymous users2024-02-04

    In C C++, memory is divided into 5 zones: heap, stack, free store, global static store, and constant store.

    If your two statements appear in the global part, then the i is stored in the global static store; If it appears in a local function, then i is stored in the stack. How can it be understood?

    The things in the stack automatically allocate memory space and automatically release the memory, while the things in the heap have to be manually allocated as long as the memory is used, and the malloc function works at this time.

    Stack: This is the store of variables that are allocated by the compiler when they are needed and automatically clear when they are not needed. The variables in it are usually local variables, function parameters, and so on.

    Heap: It is those memory blocks allocated by new, their release compiler does not care, and is controlled by our application, generally a new will correspond to a delete. If the programmer does not release it, then the operating system automatically ** after the program ends.

    Free Storage: Blocks of memory allocated by malloc and the like, which are very similar to heaps, but use free to end their lives.

  5. Anonymous users2024-02-03

    A stack, also known as a stack, is an arithmetic-constrained linear table. The restriction is that inserts and deletes are allowed only on one end of the table. This end is called the top of the stack, and conversely, the other end is called the bottom of the stack.

    Inserting a new element into a stack is also known as entering the stack, entering the stack or pressing the stack, which is to put the new element on top of the stack element to make it a new top element; Deleting an element from a stack, also known as stacking or destacking, is the process of removing the top element of the stack so that its neighbors become the new top element.

    Heap, a section of memory that is completely independent of the current function or stack frame. If you have some variables declared in a function, and you want them to be present when the function completes, you can put those variables in the heap. Stacks are less clearly structured than stacks.

    The pile can be used as a "heap" of gadgets. The program can add new things to this "heap" at any time, or modify things that are already in the heap.

  6. Anonymous users2024-02-02

    Common variables, arrays, pointers, etc., used in **, use memory called "heap", while parameters passed when calling functions use "stack" memory. This is a matter of system management, and in the first place, programmers don't need to care about that.

  7. Anonymous users2024-02-01

    In the computer field, stacking is a concept that cannot be ignored, but many people, even computer professionals, do not make it clear that stacks are actually two data structures. A stack is a data structure in which data items are arranged sequentially, and data items can only be inserted and deleted at one end, called the top of the stack. Key points:

    Heap: Order: Last-in First-Out

  8. Anonymous users2024-01-31

    Difference Between Heap and Stack:

    1. Difference in stack space allocation:

    1. Stack (operating system): The operating system automatically assigns and releases the parameter values of functions, the values of local variables, etc. It behaves like a stack in a data structure.

    2. Heap (operating system): Generally distributed by the programmer, if the programmer does not release, the program may end by os**, and the distribution method is similar to a linked list.

    2. Differences in stack caching methods:

    1. The stack uses a first-level cache, which is usually in the storage space when it is called, and is released immediately after the call;

    2. The heap is stored in the second-level cache, and the life cycle is determined by the garbage algorithm of the virtual machine (not that it can be orphaned once it becomes an orphan). So the speed of calling these objects is relatively low.

    3. Differences in stack data structures:

    Heap (data structure): The heap can be thought of as a tree, e.g., heap sorting;

    Stack (data structure): A first-in, last-out data structure.

  9. Anonymous users2024-01-30

    Difference Between Heap and Stack:

    1. Difference in stack space allocation:

    1. Stack (operating system): automatically allocated and released by the operating system.

    Store the parameter values of the function, the values of local variables, etc. It behaves like a stack in a data structure.

    2. Heap (operating system):

    Generally, the programmer assigns the release, if the programmer does not release, the program may end by os**, and the allocation method is similar to a linked list.

    2. Difference in stack caching methods: Wheel core god.

    1. The stack uses a first-level cache, which is usually in the storage space when it is called, and is released immediately after the call;

    2. The heap is stored in the second-level cache, and the life cycle is determined by the virtual machine's La's local garbage algorithm (not once it becomes an orphan object, it can be **). So the speed of calling these objects is relatively low.

    3. Differences in stack data structures:

    Heap (data structure): The heap can be thought of as a tree, e.g., heap sorting;

    Stack (data structure): A first-in, last-out data structure.

Related questions
5 answers2024-03-22

It's all as simple as that, have you ever learned C!

11 answers2024-03-22

But multiplication and division! It's called Wow!

7 answers2024-03-22

In family education, parents need to pay attention to and do a good job in the following aspects: >>>More

11 answers2024-03-22

Take a little E on the bottom edge of the trapezoidal ABCD to make the circumferences of ABE, BCE, and CDE equal, and verify: BC=AD 2. >>>More

3 answers2024-03-22

1. When a donkey is walking in the field, he hears the chirping of insects in the grass, and likes it very much, so he wants to imitate their chirping. Ask the insect and say, "Your usual food is na, and it sounds so good?" >>>More