About the values of uninitialized variables in the C language

Source: Internet
Author: User

We have just learned C programming when often encountered "Hot hot hot ironing hot hot hot hot hot hot hot ironing hot hot hot hot ironing hot ironing", this is why.
First from the last time a company written, at that time, there is a test on the issue of variable initialization. Defines an int type value outside the main function (global) and inside (local). And then there's no assignment, just print it out and ask what the output is. That would only know the global default is 0, the local is a negative very large number, but also thought to be the smallest integer. After coming back to try, the local int default is-858993460, or 0XCCCCCCCC.
But why the local default is 0XCCCCCCCC and not the other.
Check some information, found that the version of VC will be uninitialized pointer automatically initialized to 0xCCCCCCCC, rather than let it go randomly, that is because the purpose of the debug version is to enable programmers to find errors earlier, the data on the stack on the initialization of 0XCC, In other words, if the local variable is not initialized, then the debug version will be 0xCC, if the initial value of the wild pointer is uncertain. The Chinese character "hot" code is exactly 1100110011001100, which is why the beginner will appear "hot", because it will often forget to assign value or array out of bounds. While the global variable link has allocated space, when the program runs, the operating system loader, responsible for the linker assigned to the global variables of the virtual memory space, mapped to a zero-initialized page, so was initialized to zero. The global and static default initialization is implemented by the loading mechanism. Also: uninitialized symbols are in the BSS segment of the target file, and the initialized symbol is in the data section.
Local variables exist in (the stack), and global variables exist in the (static area), and dynamic request data exists in (the heap).

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.