Linux under C programming: Huawei C language Face test questions variable

Source: Internet
Author: User
Tags variables linux

Huawei C Language interview questions:

The local variables of the program exist in (the stack), and the global variables exist in the (static area), and the dynamic request data exists in (the heap).

A little summary:

1, on the stack, the most impressive is doing uboot transplant, when you are ready to enter the C code, you must give C code a good operating environment, one of the important thing is to set up the stack.

2, on the static memory allocation and dynamic memory allocation and the difference between the process

1 The static memory allocation is completed at compile time, does not need to occupy CPU resource, the dynamic allocating memory is completed at runtime, the allocation and release of dynamic memory need to occupy CPU resources;

2 The static memory allocation is distributed on the stack, the dynamic memory is allocated on the heap;

3 Dynamic memory allocation requires the support of pointers or reference data types, while static memory allocation is not required;

4 The static allocation of memory needs to determine the size of the memory block before compiling, while dynamic allocation of memory does not need to determine the memory size before compiling, according to the RUN-TIME environment to determine the size of the required memory block, as needed to allocate memory. You can say that static memory allocations are allocated on a schedule, while dynamic memory allocations are on demand.

5 Static allocation of memory is the control of memory to the compiler, and dynamic memory is the control of memory to the programmer;

To sum up, the static allocation of memory is suitable for compile-time to determine how much memory needs to occupy the situation, while it is not possible to determine the memory demand at compile time, the dynamic allocation memory can be used, but the static allocation memory is more efficient than the dynamic allocating memory because of the extra overhead for dynamic memory allocation and release; The level of dynamic memory management relies heavily on the level of programmers, which can cause memory leaks if improperly handled.

View a full set of articles: Http://www.bianceng.cn/Programming/C/201212/34807.htm

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.