"C + + Primer" Reading notes-fourth chapter expression

Source: Internet
Author: User

Statement:

    • The contents of the text collected and collated from the "C + + Primer Chinese version (5th edition)", the copyright belongs to the original book.
    • The best way to learn a programming language is to practice programming.

1, the expression is composed of one or more operands, evaluates the expression will get a result. Literals and variables are the simplest expressions, and the result is the value of literals and variables. Combining an operator with one or more operands can produce complex expressions.

2. Pointers cannot be converted to floating-point numbers.

3, an lvalue expression of the job search result is an object or a function, however, the constant object as the representative of some of the left value can not actually be used as the left operand of the assignment statement.

4, in the division operation, if the two operands of the same symbol, the quotient is positive, otherwise negative. C++11 the new standard stipulates that the negative value of the quotient of 0 rounding (direct resection of the small number of parts).

5, Short-circuit evaluation: logic and logic or the left operand is the first to find the value of the right side, when and only if the left operand cannot determine the result of the expression, the value of the right-hand object is evaluated.

6. For each object in a multiple-assignment statement, his type is the same as the object type on the right, or it can be converted by the type of the object on the right.

7. Assignment statements are often present in conditional statements because the assignment operation has a lower priority value. , so the assignment section is usually enclosed in parentheses.

8, the post-increment operator takes precedence over the dereference operator, and *pbeg++ is equivalent to * (pbeg++).  cout<<* (pbeg++) <<endl; Outputs the element that the Pbeg begins to point to, and moves the pointer forward one position.

9. member access operator: The point operator gets a member of the class object, the arrow operator is related to the point operator, and the expression Ptr->mem equivalent to (*ptr). Mem:

1 intMain () {3 stringS1 ="A String";4 string*p=&S1;5   intn =s1.size ();6   intn = (*p). Size ();7   intn = p->size ();//The meaning of the three n is the same.8cout<<n<<Endl;9 return 0;Ten}

10. The nesting of conditional operations is best not to exceed two to three layers.

11. pre-and post-built versions

++i

i++

The predecessor version changes the value of the operand and returns the changed object.

A post-build is a copy of the original value that is stored first, and then the value of the operand is changed.

11. The bitwise operator acts on an operand of the integer type and regards the operand as a collection of bits.

12. Thesizeof operator Returns the number of bytes that an expression or a type name occupies. There is no need to provide a specific object, because you want to know the size of a class member without actually getting the member.

  · The char type is sizeof with a result of 1.

  · The size of the space occupied by the referenced object is performed by sizeof on the reference type.

Performing a sizeof operation on a pointer gets the size of the space occupied by the pointer itself.

  · Performing sizeof on the dereference pointer does not require a valid pointer to the size of the space occupied by the object pointed to by the pointer.

Performing the sizeof operation on an array results in the size of the space occupied by the entire arrays, which is equivalent to performing a sizeof operation once for all elements in a logarithmic group and summing the result. Arrays are not replaced with pointers for processing.

  · The string object or the vector object performs sizeof only returns the size of the fixed part of the type, and does not calculate how much space the elements in the object occupy.

1Sales_data Data, *p; 2 3 sizeof(Sales_data);//Store the size of the space occupied by the Sale_data type Object4 5 sizeofData//the size of the data type. namely sizeof (Sales_data)6 7 sizeofP//the size of the space the pointer occupies8 9 sizeof*p;//The size of the space of the type that the pointer refers to, namely sizeof (Sales_data)Ten  One sizeofData.revenue//sales_data revenue member corresponds to the size of the type A  - sizeofSales_data::revenue//another way to get revenue size

13, Implicit conversion : C + + can not directly add two different types of values, but first based on the rules of type conversion to try to unify the object type after evaluation.

The loss of precision should be minimized. If there are both integers and floating-point numbers, the integers are converted to floating-point numbers.

14. Explicit conversion:

Static_cast: Any explicitly defined type conversion, as long as it does not contain the underlying const, can be used static_cast

Const_cast: Only the underlying const of the operand can be changed.

15, this part of the content is relatively basic, simple. To summarize less. The weekend has been played without reading, progress is already slow. Hold on, please. And along with the blast.

"C + + Primer" Reading notes-fourth chapter expression

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.