Basic knowledge of C + +

Source: Internet
Author: User

1. The C language has a standard: the definition of a variable is generally written at the beginning of the function

2, the variable must be initialized, or the use of dirty data, for the following reasons:

If the variable is not initialized, it can be compiled successfully, but when executed, it is likely to error, we need to know how the operating system manages memory! Whenever an application is opened, the operating system allocates memory for it, memory addresses and memory units, and when the application initializes, it writes data to the memory unit, and when the operating system recycles, it does not empty the memory unit, so there is a lot of junk data. If the variable is not initialized, it will read the garbage data by default, some junk data will cause the program to crash, vc++2010 compiler can be aware that the variable is not initialized, debugging error, so the variable must be initialized before use!

3 . Two ways to define a constant pi:

1, #define Pai 3.14159

2, const float PAI 3.14159;

The first way: is to define PI as a symbol, at this time Pai is only 3.14159 alias, during compilation with 3.14159 to replace the value of pi, define equivalent to replace.

The second way: is to define PI as a variable, but tell the compiler its value is fixed, if in the program to try to modify its value, at compile time will error!

Basic knowledge of C + +

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.