Some common misunderstandings in the C++--c language

Source: Internet
Author: User

In the 1.C language, the compilation is for a single source file, and the link is for the entire project.

2. The variable definition should not be placed in the header file , otherwise it will cause a link error . The header file should only place the type definition, the declaration of the function, and the declaration of the variable.

3. If you do not add a preprocessing statement such as #ifndef in the header file, you are likely to create a compile-time error with a duplicate type definition.

4. The function declaration in the header file is intended to provide the compiler with a reference to the function prototype, which is not required.

5. The pointer contains dual information:

A) The value of the pointer itself represents the starting position of the pointing memory

b) The type of pointer indicates the size of the unit pointing to the memory.

6.C-language memory does not have a property, and what type of pointer points to it, it explains why the type of data.

7. The key to exchanging two variables is to pass their pointers, such as the T-type pass t* as a parameter.

8. When an array is passed a parameter, a one-dimensional array such as int a[10] , the pass parameter can use int*, if it is a two-dimensional array int a[3][10], then the pointer of one-dimensional array should be passed Int (*a) [10 ].

9. Two-dimensional array int a[10][5], a[i] is equivalent to * (a+i), while a[I [j] is equivalent to * (* (A + i) + j) .

size End problem:TCP Transport, for strings do not need to consider the size of the end, for int , etc. need to consider. In short , there is no need to consider the size side of the data in bytes logical units.

11. The function pointer contains two kinds of information, the first is the memory address of the function, the second is the type information, contains the function's parameter list and the return value. (There is a simple introduction to function pointers in the previous article)

Some common misunderstandings in the C++--c language

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.