C + + Primer Plus (quad)--composite type

Source: Internet
Author: User

  1. You can only initialize an array when you define it, you cannot assign an array to another array, but you may assign a value to an array element by using the subscript, but you can assign a string object to another string object

  2. If only one part of the array is initialized, the other elements are automatically set to 0

  3. C++11 can contain nothing in the initial curly braces, which will set all elements to 0.

  4. C++11 suppress narrowing conversions when array list is initialized

  5. C-style string ends with a, not a char-terminated character array not a string

  6. Any two string constants separated by whitespace (spaces, tabs, newline characters) will spell themselves into a

  7. The sizeof operator indicates the length of the entire array, while strlen () indicates the length of the string stored in the array

  8. CIN uses blanks (spaces, tabs, newline characters) to determine the end position of a string, and for word

  9. The Get () function and the getline () function of CIN are line-oriented:

    The Getline () function discards a newline character and stops reading when a specified number of characters-1 is read or when a line break is encountered

    The Get () function preserves the newline character, and you use the parameterless get () function to read the newline characters before reading the characters again, or you can use the clear () function to restore the input

  10. You can use C-style strings to initialize a string object, use CIN to store keyboard input in a String object, use cout to display a string object, and use array notation to access the characters stored in a string object

  11. C + + takes "(and)" as a qualifier, uses the prefix r to identify the original string (not escaped), and can be used to create custom characters between the original delimiter, with the addition of spaces, opening parenthesis, closing parenthesis, Slash, and other characters outside the control character.

  12. C + + allows you to omit the keyword struct when declaring struct-body variables and use the member operator. To access individual members

  13. C + + does not advocate the use of external variables, but advocates the use of external structure declarations

  14. struct initialization uses a comma-delimited list and encloses these values in curly braces.

  15. C + + allows you to specify a struct member that occupies a specific number of bits, the struct member's field type is integer or enumeration, followed by a colon, a number followed by a colon, so that it can be created on a hardware device with a register corresponding to the data structure, but bit fields are usually used in low-level programming.

  16. A community can store different data types, but only one of these types can be stored at the same time, saving space when data items use two or more data types, and are often used in operating system data structures or hardware data structures.

  17. C++enum provides another form of creating symbolic constants. In the case of no casting, only the enumeration that is used when defining the enumeration is assigned to the variable of such enumeration, and when the arithmetic operation, the enumeration is automatically converted to int, whose result type is int and must be cast to be copied to the enumeration variable

  18. Each enumeration has a range of values, and by casting, any integer value in the range of values can be blessed to the enumeration variable, even if the value is not an enumeration value, the definition of the enumeration range is calculated to include the enumeration of the maximum value of 2 of the n-th square, for example, the maximum value is 108, the maximum value of 128, Its minimum value is-6, the lower limit of its minimum value is-8, the value range is -8~128

  19. To get the address of a regular variable, simply use the address operator &

  20. The difference between object-oriented programming and traditional procedural programming is that OOP emphasizes the operational phase of making decisions.

  21. When using a regular variable, the value is the specified amount, and the address is a derivation; the pointer is the opposite, the pointer name gets the address, and the value is the amount of the derivation. * is an indirect value or dereference operator, applying it to a pointer can get the value at that address

  22. In C + +, int* is a composite type, a pointer to int, and a * for each pointer variable name.

  23. Initialized in a declared statement, the pointer is initialized, not the value it points to.

  24. When you create a pointer in C + +, the computer allocates memory to store the address, but does not allocate memory to store the data that the pointer points to. The golden rule of using pointers is to initialize the pointer to a certain appropriate address before the pointer applies the dereference.

  25. The pointer is not an integral type and cannot be simply assigned to a pointer, and the number should be converted to the appropriate address by forcing the type conversion

  26. The value of the variable is stored in the memory area of the stack, and new allocates memory from the memory area of the heap or free storage area

  27. Use Delete to free memory, do not delete the pointer itself, do not release the memory blocks that have been freed, and do not release the memory obtained by the variable declaration

  28. Do not create two pointers to the same block of memory, as this will increase the likelihood of the error removing the same memory block two times

  29. When you use new and delete, you should follow these rules:

      1. Do not use Delete to release memory not allocated by new

      2. Do not use Delete to release the same block of memory two times

      3. If you use new[] to allocate memory for arrays, you should use delete[] to free

        If you use new to allocate memory for an entity, you should use Delete to release

      4. Applying delete to a null pointer is safe

  30. Both C and C + + use pointers to handle arrays, arrays and pointers are basically equivalent, the difference is that the value of the array name is a constant, cannot be modified, the value of the pointer is a variable, can be modified; the sizeof operator is used to get the length of the array, while the pointer is applied to the length of the pointer.

  31. Adds a pointer variable to 1 o'clock, and its incremented value equals the number of bytes that the pointing type occupies

  32. When an array is created using an array declaration, a static binder is used, and a dynamic union is used when an array is created using the new[] operator.

  33. Using the square brackets array notation is equivalent to dereferencing the pointer

  34. For strings in arrays, string constants enclosed in quotation marks, string constants that are described by pointers, they are handled by passing their addresses

  35. Do not use string constants or pointers that are not initialized to receive input.

  36. C + + has three ways of managing data memory:

      1. Automatic storage--local variable--stack

      2. Static storage, variables declared outside of a function or static storage, variables using the static keyword

      3. Dynamic storage of variables---heap->new/delete declarations

  37. Vectors use new and delete to automatically manage memory

  38. When an array object is initialized, the parameters that initialize the number of elements can only be constants.

  39. Arrays and array classes are stored in the stack, and vectors are stored in the heap.

  40. C + + does not check for out-of-bounds errors, and the difference between the bracket notation and the member function at () is that at will catch illegal indexes during run time, and the program will break by default, but run longer.

  41. c++98 New Standard Template Library STL provides a template class vector, which is a substitute for dynamic arrays;

    C++11 provides a template class array, which is a substitute for fixed-length arrays






C + + Primer Plus (quad)--composite type

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.