C + + Primer Plus (v)--loops and relational expressions

Source: Internet
Author: User
Tags first string

  1. The precedence table indicates that the assignment operator is a right-to-left combination

  2. It's a good idea to define a const value to represent the number of elements in an array.

  3. The same value of the same statement is incremented or decremented multiple times, and C + + does not define this behavior, which means that the statement produces different results on different systems.

  4. The prefix operator is more efficient than the postfix operator

  5. The prefix operator and the dereference operator have the same precedence, combining right-to-left;

    The suffix operator takes precedence over the prefix operator and the reference operator, in a left-to-right manner.

  6. When the C + + syntax allows only one expression, you can use the comma operator to combine several expressions into one, but you cannot group two declarations, and you can use a declaration statement expression to create and initialize two variables.

  7. In all operators, the precedence of a comma expression is the lowest: it ensures that the first expression is evaluated first and then the second expression, whose value is the value of the last expression.

  8. C + + provides 6 operators to compare numbers, or they can be used for characters, but not for C-style strings, but can be used with string class objects.

  9. C-style strings are compared by applying the strcmp () function to return an assignment if the first string is less than the second, if it is greater than the return positive value, if the equality returns 0, that is, equal to false.

  10. A C-style two string may be the same even if stored in a different length array, because the C-style string is defined by the trailing null character, not the length of the array in which it resides.

  11. C + + typically uses a For loop for loop counting, and a while loop when it is not possible to know in advance how many times it will be executed.

  12. The condition is considered true when the test condition is omitted in the For loop.

  13. Write a delay loop:

      1. The clock () function in the ANSI and C + + libraries Returns the system time that is used after the program starts executing.

      2. The header file CTime provides a constant clocks_per_sec that is equal to the number of system units contained per second

      3. Divide the system time by the constant to get the number of seconds, or multiply the number of seconds by that constant to get the time in system time

      4. The clock_t type converts the resulting product result into a result appropriate to the current system

  14. C++11 adds a range-based for loop:

      1. Show only elements:

        For (type: array) loop body

      2. To modify an array element:

        For (& type: array) loop body

  15. Use CIN for Input:

      1. Raw cin Input: Cin>>char

        1. Ignore spaces and line breaks, tab characters

        2. The input is buffered, and the input is sent to the program only after the user presses the ENTER key.

      2. Use Cin.get (char) for input: Read spaces, line breaks, tab characters


properties
cin.ge T (CH) ch=cin.get ()
the way to transfer the input characters assign parameter ch Assign the function return value to CH
is Tream (True if bool conversion is performed) The return value of the function when it reaches EOF istream (false after bool conversion) eof
      1. After EOF is detected, CIN sets two bits (Eofbit and Failbit) to 1, which can be cin.eof () to see if Eofbit is set, and Cin.fail () can see if Eofbit or Failbit is set

      2. The IStream class provides a function that converts a IStream object to a bool value, which is automatically called when Cin appears where the bool value is now required.

      3. Because EOF is not a valid character encoding, it may not be compatible with char types. If you want to test EOF with Cin.get (), you must assign the return value to the int variable, which is cast to the char type when it is displayed.

      4. The main purpose of get () is to convert Stdio.h's GetChar () and Putchar () functions to iostream cin.get () and Cout.put ()



C + + Primer Plus (v)--loops and relational expressions

Related Article

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.