Tips for one sentence (continuously updating ing ~)

Source: Internet
Author: User

1. When the parent function passes the array to the sub-function, the total length of the array cannot be obtained during the sub-function. If it is a char string, strlen can obtain the actual length of the string. sizeof is unreliable and may be any result.

2. segment faults are considered to be one of the most common errors in Linux applications. This error occurs when the program attempts to access the memory not allocated to it and terminates due to a segment violation.

3. Some subtle bugs in ansi c, such as int and unsigned int comparison. Int will be upgraded to unsigned int, and the number of int such as-1 will become huge. For example, the following code:

# Include <iostream> using namespace std; int main () {unsigned int p = 1; int a =-1; if (a <p) cout <"right "; else cout <"wrong"; return 0 ;}

The result output is wrong.

4. if the class object is of the const type, you can only call the const function in the class. If the class pointer is of the const type, you can only call the const function in the class. that is, for a const object, the c ++ compiler cannot call member functions unless the member functions are declared as const itself, even if they do not modify the object to obtain member functions. In addition, the compiler does not allow member functions declared as const to modify objects.

To specify a function as a const, you must specify both in its prototype and in its definition. The method is to insert const before the left curly brackets after the function parameter list and the function body;

5. If there are too many lines of content, you can use \ [Enter] to extend to the next line. This applies to c/c ++ and shell programming.
6. interfaces in Java can be declared, but cannot be instantiated. It can be used as a subclass handle to point to the subclass instance, but it cannot be used to call the unique method of the subclass.

7. one common feature of adapter in STL is that iterator is not supported.

8. When multimap inserts the same key in STL, it automatically aggregates data by key internally.

9. for most CPUs, the integer double of the CPU length is faster, so if these members are not enough to add up to this integer multiple, the compiler may insert additional content to add up to this integer multiple, in addition, sometimes adjacent members may be inserted with spaces for this purpose, which is called "padding ). Therefore, the C ++ standard strictly stipulates that the Members are arranged in the class-defined order, but they are not required to be closely arranged in the memory.
Based on the above two points, we can say that we use sizeof to operate on the class name. The result is the size of the bytes occupied by the class object in the memory. Because the static member variables are not stored in the object, therefore, this result is equal to the sum of all non-static data members (excluding member functions) plus the additional bytes added by the compiler. The latter depends on different compiler implementations, and the c ++ standard does not guarantee this.

The result of sizeof must be an integer multiple of 4.

10. object size = Vptr (more than one) + Size of all non-static data members + Aligin byte size (dependent on different compilers)

11. In C, add a space before % to indicate "Force scan leading blank"

12.

Valid numeric absolute value range of Type length (bit)
Float 32 6 ~ 7 10 ^ (-37 )~ 10 ^ 38
Double 64 15 ~ 16 10 ^ (-307 )~ 10 ^ 308
Long double 128 18 ~ 19 10 ^ (-4931 )~ 10 ^ 4932


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.