I. Coding specifications BASIC Data Types
Coding Specifications
Any programmer, should have good coding habits, convenient for future code readability and maintenance
It is common for coding specifications to have
Hungarian Naming Act
Camel-Case
Hungarian Naming Act :
is a kind of variable naming rule in computer program design, and it can be subdivided into: system Hungarian nomenclature and Hungarian applied nomenclature method.
Hungarian nomenclature is a language-independent feature and is used for the first time in BCPL languages. Since BCPL is only a data type of machine word, the language itself does not help programmers to remember the types of variables. The Hungarian nomenclature solves this problem by clarifying the data type of each variable.
In Hungarian nomenclature, a variable name starts with one or more lowercase letters that help to memorize the type and purpose of the variable, followed by whatever name the programmer chooses. The first letter of this second part can be capitalized to distinguish the preceding type from the letter (see Camel case).
For example: I_de f_fd db_d Ch_c The first given information can be very clear until what type.
Facilitates readability of the code
Camel-Case :
Camel Case (camel-case,camel,camel), a set of naming conventions (conventions) when a computer program is written.
When the variable name and function name are linked together by two or more words, and the unique identifier is made up of a "camel case", you can increase the readability of the variables and functions.
For example: Addsum () Subvalue Binarrayserach () so you can see the effect of each function
For example, the sum of the first plus one number is the second minus the value of the third binary array lookup.
When you get an editor,
The first step:
Say that his tab is set to the SPACEBAR to replace, so that the code under any platform will look the same.
Step Two:
When you write code, each code needs to be indented in the first line if it relies on the relationship of the previous layer of code.
Step Three:
Tell the editor to set the line to ensure that the code is not exceeded, which helps the readability of the Code
Fourth Step:
When you write the source code, add comments and comments to the above requirements are:
Requirements (can be project requirements, functional requirements, what to say)
Time (the time you modified)
Name (When you change it, plus the time, plus your name)
two ,
Common uses of scanf functions
S canf ("%d,%d", &a,&b);
For the scanf function, what do you add when you scan the input, what is the delimiter to enter?
General scanf default is a space or carriage return is a delimiter.
S Regular expressions can be placed in the CANF function
Common regex expressions are:
S canf ("%[0-9]d", &a); The delegate can only enter 0-9, not the output
S canf ("%a-z]d " , &a); delegates can only enter a-Z, not output
S canf ("%[^5]d", &a); representative cannot enter five, input five will not scan in
The difference between scanf and sscanf
S CANF is a scan of input from a standard input device.
S scanf is a scan of input into a string from a standard input, and he can also use regular expressions. It is often used.
three, the memory structure of the general brief
Any one program access is theoretically 4G of memory
But the operating system accounts for 2g of memory at this time this memory is not readable and modified, because this block becomes Ring3 can also become R0
Unless you have permission to the operating system.
and the low 2g is not the program can directly access the
can also be divided into low 64 and high 64
These are the buffers that the user area uses to interact with the operating system
Now the rest of the memory can be divided into
Stack segment
Heap Segment
Code Area
Data segment
Which is what we programmers often say about the four areas of memory
And now your program runs out of memory is not all for you, but you need how much I give you.
This ensures that the program can be opened 2-30 a bit.
Here's a look at the memory model
Four. Basic data Types
There are a lot of data types compared to the C language and the same type
Where the long type of __int64 is a non-standard type, if from a commercial point of view, Microsoft can firmly hold
These people's platforms are all dependent on their own. It is not portable because of non-standard types of code.
The difference between overflow and rounding
Overflow: is a description of the signed data, meaning that when the data to the maximum value, if at +1 then the data will overflow there may be a nominal negative value, recovery costs. It may not be possible to recover.
Carry:
The carry is a description of the unsigned data, and when the data exceeds the data, a carry is generated. The current value is still valid. Carry data can be obtained by some means.
five characters and strings
The storage and interaction of character wear:
A total of 2 concepts are presented.
One is:
C-language style, after the character ends with 0, which represents a string.
The other is Pascal style
The first few (not sure, typically 2-bit) a given size, followed by storing the same size as a character, forming a string
Their pros and cons
C Language:
Advantage: Flexibility is relatively high, especially when the network communication, as long as not to end with 0, then you can transfer any character.
Disadvantage: The disadvantage is more obvious, if you want to find the nth character, then one to find,
Pascal:
Advantages:
Fixed length, access n high efficiency, can be accessed as a springboard
Disadvantages:
Lack of flexibility, if used in the network, then the transmission can only be transmitted after the new, can not be transmitted.
And Microsoft is a combination of the 2 features
The front table type, followed by the end of 0, (more cunning) the advantage of doing so is that compatibility is higher, and your own products sell better.
six, character and string differences
The difference between ' a ' and ' a '
The character A is accessible by ASCII-encoded
And string A is the first address of the referenced string
Seven. Specification of identifiers
The specification for identifiers is: In the C language, the definition identifier can only be a numeric letter underline
Where numbers do not start
For example:
2ac This definition is wrong, so that the 2 is not clear what to do.
in addition to regulations in the eight and C languages
Rule-to-0 rounding
3/2 = 1 in mathematics is 1.5
In mathematics, there is the meaning of rounding up and rounding down.
is 1.5 if you take the whole thing down, it means to take the largest integer, which is 2.
Rounding up is the largest integer that is not less than your own, which is 1.
Therefore, in C language, the right to move the symbol must be judged whether the quotient is negative
If it is a negative number then the error will occur because the regular style is rounded to 0.
1.5 to 0 rounding, is to discard decimal 0.5
Nine,% of the principle
We all know the effect of the% number.
8%3=2
-8%3=-2
8%-3=2
-8%-3=-2
The calculated result is related to the left operand symbol, and the left operand is the symbol of what the remainder is.
But the principle we don't know,
In fact, the principle is
A/b=q...r
A = Q*b+r;
R = a-q*b;
Value found after substituting
8/3=2..2
8 = 2*3+2
Remainder 2 = 8-2*3
So the result is 2.
C Language _ second _ specification and common data types