The C language contains data types as shown in the following:
I. Data types and "molds"
The six keywords short, int, long, char, float, double represent the six basic data types in C language.
How to understand them? For example: Have you seen that thing with Lotus root? (Never seen?) Briquettes have always seen it.) That thing called the Lotus, holding it in the good coal heap so a click, a briquettes out. Radius 12cm,12 a hole. The size of the briquettes of different types of coal-mine is not the same, the number of holes is not the same. This lotus is actually a mold.
Now we associate, short, int, long, char, float, double these six things are not very similar to different types of lotus? Take them in the memory of a click, different sizes of memory allocated well, of course, don't forget to give them a nice name.
On a 32-bit system, the memory size of short clicks is 2 bytes;
int clicks out of memory size is 4 bytes;
The memory size of a long click is 4 bytes;
The memory size of float click is 4 bytes;
Double clicks out of the memory size is 8 byte;
The amount of memory that char clicks out is 1 bytes.
(Note that this refers to the general situation and may vary depending on the platform,specific platform can be tested with the sizeof keyword)
Very simple, huh? Is it cool? is very simple, and indeed very good, but the problem is that you pull out so much memory block, you can not give him a name called x1,x2,x3,x4,x5 ... or 1th Changjiang River, No. 2nd Changjiang River ... it. They look like this (not your boss, Dick, old three ...), and after a while you'll forget which name matches which memory block (who married who?). ^_^). So it's absolutely important to give them a good name. Let's take a look at what kind of name is good.
Ii. naming rules for variables
1, the name should be intuitive and can be spelt, expected to understand the text, easy to remember and read.
Identifiers are best used in English words or combinations, and pinyin is not allowed. The English words in the program are generally not too complicated, the words should be accurate.
2, the length of the name should conform to the "Min-length && max-information" principle.
C is a concise language, and the name should be concise. For example, variable name maxval is more useful than maxvalueuntiloverflow. The length of the identifier is generally not too long, longer words can be shortened by removing the "vowel".
In addition, English words as far as possible not abbreviated, especially the use of professional nouns, if there are abbreviations, in the same system, the same word must use the same notation, and indicate its meaning.
3. When an identifier is made up of multiple words, the first letter of each word is capitalized and the rest is all lowercase. Like what:
int currentval;
The name looks clearer, much better than a long string of characters.
4, as far as possible to avoid the name of the number of numbers, such as value1,value2, unless the logic does need to number. For example, when driving the development of the PIN name, non-numbered names instead of bad.
Beginners always like to use a numbered variable name or function name, which looks simple and convenient, but is actually a time bomb. This habit must be changed by beginners.
5. Add a range qualifier to a global variable or function that is used in conjunction with multiple files (the module name (abbreviated) is recommended as the range qualifier).
Naming rules for (gui_, etc) identifiers:
6.The identifier name is divided into two parts: the canonical identifier prefix (suffix) + meaning identification. Non-global variables can be prefixed without using a range qualifier.
7, scope prefix naming rules.
8, data type prefix naming rules.
9, meaning to identify the naming rules, variables named using a noun phrase, the function of the name of the use of verb phrases. For example:
Variable meaning identifier composition: target word + verb (past participle) + [adverbial] + [destination];
function meaning identifier composition: verb (general present) + target word +[adverbial]+[destination];
10, the program must not appear only by the case of a similar identifier. For example:
int x, x; Variable x is easily confused with X
void foo (int x); function Foo is easily confused with Foo
void FOO (float x);
Here's another thing to pay special attention to is the difference between 1 (number 1) and L (Small Letter L), 0 (number 0), and O (lowercase letter O). The two pairs are really hard to tell, and one of my colleagues has been tossed about by this question once.
11, a function name is forbidden to be used in other places. For example:
#include "C_standards.h"
void foo (int p_1)
{
int x = p_1;
}
void static_p (void)
{
int foo = 1u;
}
12. All macro definitions, enumeration constants, read-only variables are all capitalized, and the words are divided by underscores. For example:
const int max_length = 100; This is not a constant, but a read-only variable, please look backwards
#define FILE_PATH "/usr/tmp"
13, considering the habitual problem, local variables can be used in general naming, only N, I, J and so on as a cyclic variable use.
Be sure not to write code like this:
int p;
char i;
int C;
char * A;
Generally speaking, n,m,i,j,k are used to denote variables of type int, such as C,ch, which represent character type variables; Of course, this is only a general habit, except i,j,k and so on can be used to represent the loop variable, the other character variable name try not to use.
14, the definition of variables at the same time must not forget the initialization. When you define a variable, the compiler does not necessarily empty the memory, and its value may be invalid data. This is a very detailed discussion in the memory management chapter, please see.
15, the operation of different types of data should pay attention to the precision expansion problem, the general low-precision data will be extended to high-precision data.
C language Basic data type short, int, long, char, float, double