C ++ Primer Plus study Note 1, cprimerplus

Source: Internet
Author: User

C ++ Primer Plus study Note 1, cprimerplus
C ++ Primer Plus study Note 1

Chapter 2 start to learn C ++
1. Control letter endl
If a string is displayed, it contains a line break instead of adding an endl at the end, which can greatly reduce the input. If you want to generate a blank line, we think endl is more convenient.
2. In C and C ++, spaces, tabs, and carriage return characters cannot be placed in the middle of the element, or carriage return characters in the middle of the string. However, spaces can be placed in the middle of the string.
3. Why does the int main () main function require a return value of 0? Because we can regard the computer hyping system as a calling program, the return value of main () is not the other part of the program, but is returned to the operating system.
4. C ++ statements include declaration statements, value assignment statements, message statements, function calls, function prototypes, and return statements.

========================================================== ==========================================================
Chapter 3 process data
1. variable name naming rules
Only letters, numbers, and underscores (_) can be used in the name. The first character of the name cannot be a number. It is case sensitive. The C ++ keyword cannot be used as the name; the variable naming scheme is the same as the function naming scheme. Sometimes a simple letter prefix is usually added before the name to describe the type of the variable, for example, str or sz represents a string ending with a null character, B represents a Boolean value, p represents a pointer, and c represents a single character.
2. Sometimes you can use the unsigned type to increase the maximum value that a variable can store. Unsigned. If it is an integer, you can directly write it as an unsigned int, which is equivalent to unsigned.
3. How can C ++ determine the constant type?
If there is no special description, we all store the int type as an integer constant by default. Sometimes, the l and L suffixes after the integers are differentiated with suffixes to indicate that the integer is a long constant, u and U suffixes indicate unsigned int constants, ul indicates unsigned long, and lowercase uppercase can be used.
4. single quotation marks for characters in C ++ and double quotation marks for strings
5. Forced type conversion
(TypeName) value comes from C Language
TypeName (value) is from C ++. The idea of the new format is to make forced type conversion look like a function call.

========================================================== ========================================================
Chapter 4 composite type
1. Array
TypeName arrayName [arraySize] note that arraySize can be an integer constant or a const value, or a constant expression, but not a variable.
2. array initialization principles
1) initialization can be used only when an array is defined. hand [4] = {5, 6, 7, 9}; fals
2) An array cannot be assigned to another array hand = cards; false
3) If only part of the array is initialized, the compiler will set other elements to 0.
4) it is easy to initialize all elements of the array to 0. You only need to initialize the first element to 0. For example, long totals [500] = {0}. Note: what if we want to initialize all elements to 1? We Cannot initialize to {1}. Otherwise, only the first element is 1 and the others are 0.
3. Distinguish double quotation marks of strings from single quotation marks of Characters
Char shirt_size ='s ';
Char shirt_size = "S ";
4. Several input methods: (important)
1) string input: cin uses blank spaces (spaces, tabs, line breaks) to define the bounds of the string.
2) each time you read the input string of a row:
Line-oriented input: getline () determines the end of the input through the line break entered by the Enter key. This method is called.
To call this method, use cin. getline (name, N), note that this function can read up to N-1 characters.
Line-oriented input: get () cin. getline (name, N)
Note: Call get () twice in a row ()
Cin. get (name, ArSize );
Cin. get (dessert, Arsize );
This is not correct, because after the first call, the linefeed will remain in the input queue, so the first character displayed in the second call is a linefeed. If no help is provided, get () the line break cannot be crossed.
Normal handling method:
Cin. get (name, N );
Cin. get ();
Cin. get (name1, N );
In short, getline () is easier to use, but get () is easier to use to check for errors.
5. C ++ programs often use pointers instead of arrays to process strings.
Strcpy (charr1, charr2) replication
Strcpy (charr1, charr2) is appended to the end of the string
6. Two methods to determine the number of character strings
Int len1 = str1.size (); int len2 = strlen (charr1 );
7. Structure
Struct inflatable
{
Char name [20];
Float volume;
Double price;
}; The inflatble label becomes the name of the new type.
8. A shared object is a data format that can store different data types, but can only store one of them at the same time. That is to say, the structure can store int, long, and double at the same time, and the shared body can only store int, long, or double
9. Enumeration
Enum spectrum {red, orange, yellow, green, blue, violet, indigo, ultraviolet}
First, change spectrum to a new type name, enumerative
The braces are converted into symbolic constants, corresponding to the integer 0 ~ N. These constants are called enumeration.
10. Declare the initialization pointer
Int * ptr is traditionally written in this way
Int * ptr is written like this now
Note that each pointer variable name requires *
Int * p1, p2; create a pointer p1 and a regular int variable p2
11. Usage of new
1) when C ++ creates a pointer, the computer will allocate memory to store the address, but will not allocate memory to store the data pointed to by the pointer. In C language, you can use the library function malloc () to allocate memory. In C ++, you can still do this, but there is also a better way-the new operator.
Int * ps = new int;
......
Delete ps; // release the memory, but the pointer ps itself will not be deleted, so we need to use this pair, otherwise Memory leakage will occur. 2) use new to create a dynamic array
Int * psome = new int [10]; // new returns the address of the first element.
Delete [] psome; // Add square brackets to release an array.
3) Rules to be noted when using new and delete
① Do not use delete to release memory not allocated by new;
② Do not use delete to release one memory block twice;
③ If new [] is used to allocate memory for the array, delete [] is used to release the array;
12. When the pointer variable is increased by 1, the value is equal to the number of bytes occupied by the type to which the pointer belongs. That is to say, if pw points to the double type, when pw is increased by 1, its value is increased by 8 bytes. for short, its value is increased by 2 bytes.
13. In cout and most C ++ expressions, the char array name points to the char pointer and the String constant enclosed in quotation marks are interpreted as the address of the first character of the string.
14. To obtain a copy of the string, for example, we need to assign animal to ps
1) Allocate space ps = new char [strlen (animal) + 1];
2) Copy strcpy (ps, animal );
The difference between strncpy and strcpy is that it receives the third parameter, the maximum number of characters to be copied.
15. Use new to create a dynamic structure
Inflatable * ps = new inflatable;
When is the period operator used and when is the arrow operator used?
The rule is very simple. If the structure identifier is the structure name, the period operator is used. If it is a pointer to the structure, the arrow operator should be used. Ps is the pointer to the structure, so ps-> name; ps is the value to be pointed to, structure itself,
(Ps). volume

========================================================== ==============================================
Ended at, January 15 ,.



A notebook software? It is mainly used to record learning notes

The outlook provided by windows provides the daily Notebook function, which is easy to use.
And
The fish and fish table show is the first free desktop Widget software developed by Chinese people. Xforwarshow has a luxurious and elegant interface and powerful script engine, but occupies a very small amount of system resources. It is currently the fastest and most lightweight desktop widget tool. It adopts the plug-in mechanism, you can download a large number of Widgets on your desktop to implement functions such as weather forecast, World Clock, beautiful big icons on the desktop, calendar memos, notes, RSS news reading, cdcover player, and artistic the motto of desktop calligraphy and the goldfish used for traveling, make your Windows desktop more practical and colorful. The latest control-style Script Engine allows you to create diy widgets with unique personality!

[Features]
Supports weather forecast, daily (monthly) calendar, clock, RSS, notes, player control, Desktop shortcuts, and other functions. It also supports any combination of themes and unlimited extension of the plug-in mechanism.
Fast startup, low resource occupation, light and fast.
The original control-style Script Engine is simple and easy to use. It is the most DIY widget software.
Small, exquisite, and translucent embedded in the desktop background.
Many plug-ins are available on the home page. Double-click to automatically install the plug-in.
The built-in plug-in download browser automatically downloads and installs new plug-ins with one click.
Built-in real-time preview of the skin Editor, easy DIY personalized plug-ins, and support packaging and publishing plug-ins.
Beautiful and easy-to-use plug-in selection bar, plug-in startup animation expansion, supports fade in and fade out.
Huge user communities and Forum support.
More importantly, she is free!

: Cfishtest2.w29.1358.net/x?show_v=7.exe

An error occurred while learning c primer plus (beyond my understanding)

Scanf ("% f", weight); one less & Symbol

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.