First, the key word
1. What is a keyword
1> keyword is the C language provides a special meaning of the symbol, also known as "reserved word"
The 2> C language provides a total of 32 keywords, all of which are given special meaning by C language
Auto double int struct break else long switch
Case enum Register typedef char extern return Union
const float Short unsigned continue for signed void
Default goto sizeof volatile do if and static
Roughly browse once again, do not have to Baidu each keyword role, these keywords will often use later, when you want not to remember is difficult
2. Characteristics of keywords
1> are all lowercase
2> displays special colors in the development tool or in the Smart Text Editing tool. By default, all keywords in the C language are shown in Xcode with a violet-brown
3. What are keywords in the main function
int, return
Second, identifiers
1. What is an identifier
Identifiers are some of the symbols and names that you customize in your program. To differentiate from keywords: the keyword is the symbol that is provided by the C language by default, and the identifier is a programmer-defined
2. The role of identifiers
1) identifiers, literally understood, are symbols used to identify something, the purpose of which is to separate it from the other.
2) In fact, the function of the identifier is similar to the human name, in order to distinguish each person, at the time of each person's birth a name
3) C language is composed of functions, a C program may have more than one function, in order to distinguish these functions, each function is given a name. The name of the function is one of the identifiers. In addition to the function, the concept of "variable" will be learned later, and the name of the variable is also the identifier
3. Naming
1> naming rules (be sure to follow)
L can only be made up of 26 letters in uppercase and lowercase, 10 Arabic numerals 0~9, underline _
L Strictly case-sensitive, such as test and test are 2 different identifiers
L cannot start with a number
L can not use keywords as identifiers
2> naming conventions (best to follow)
L try to make a meaningful name, such as a complete English word, the name can be seen by others to the role of this identifier. If you do not understand English, you can also use pinyin, try not to be like ABCDE, SFSDFSDF and other such seemingly meaningless names
L If the identifier contains more than one word, you can use the Hump logo (except for the first word, the first letter of each word is capitalized): FirstName, MyFirstName, or use the underscore _ to connect: first_name, My_first_name
4. Common identifier naming errors
Legal identifiers |
Illegal identifiers |
Comments |
FromNo12 |
From#12 |
The # symbol cannot be used in identifiers |
My_boolean |
My-boolean |
The "-" symbol cannot be used in identifiers, and the underscore "_" should be used instead |
Obj2 |
2ndObj |
Identifiers cannot start with numbers |
MyInt |
Int |
"Int" is the built-in keyword |
Jack_rose |
Jack&rose |
Symbol ' & ' cannot appear in the identifier |
Gui |
G.u.i |
The identifier must appear inside the "." Separator |
Third, comments
1. What is a comment
1) Annotations are a concept that is very important in all computer languages, literally, the meaning of annotations and explanations.
2) Comments can be used to explain the meaning of a program or a line of code to facilitate communication between programmers. If I finish writing a line of code and add the corresponding comment, then people will see this comment and know what my line of code is for.
3) Comments can be any text, which means you can write Chinese
4) Note in development tools is generally red bean paste Green
2. Single-line Comment
1) The single-line comment starts with two forward slashes, that is, starts with//, can only comment one line, from//start to the end of this line is the contents of the comment
2) anywhere you can write a comment: Outside the function, inside, behind each statement
3. Multi-line annotations
Multiline comments start with/*, end with */, the contents of/* and/* are commented
4. The role of annotations
1> Annotated code does not participate in compilation
L Note is written to people, not to the computer to see. How can a computer see the Chinese we write? Therefore, when compiling the program, the comments are not compiled into the. O Destination file
L from the size of the. o file can be indirectly seen that the code after the comment is not compiled
2> checking the role of code
3> Troubleshooting Errors
5. Nested behavior of annotations
1) Single-line comments can be nested single-line comments, multiline comments
wow haha//Oh OH
/* FSDFSDF *//SDFSDFSD
2) multiline annotations can nest single-line comments
/*
Mj
Description: First C language Program
Function: This is a main function, the entry point of C program
*/
3) Multiline comments cannot nest multiple lines of comments
/* ha ha haha
*/Hee Hee * *
Oh, OH *
4) The following wording is wrong
// /*
Ha ha haha
*/
6. Importance of annotations
l want to develop a good habit of writing notes. Most project managers check the subordinate code of the first thing is to see if there is no comment, there are many companies will also check the machine test comments (the test is to give you a programming problem, a computer, in the specified time to solve problems)
L Today, you wrote hundreds of lines of code, very happy, made a very nice feature, but forgot to write the comments. After one weeks, it's normal for you to go back and look at that piece of code, which you may not be able to understand at all. If you write a comment, the situation is different, and comments can help you review the role of the Code.
You have been in a company for more than 1 years and have written 10 tens of thousands of lines of code, but you do not write a note. One day you quit and the new employee takes over your project, the first thing he must do is to read the code you wrote. But you did not write a little note, 100,000 lines of code, all in English, which will make the new employee very egg pain. Everyone has their own ideas, the idea of writing code is certainly not the same, it is very painful to see the code written by others, especially the code without comments. The way you do not write comments can greatly reduce your company's development efficiency. As a result, all formal companies attach great importance to annotations.
Iv. Data
1. What Is Data
Life is always with the data, such as weight data, blood pressure data, stock price data and so on. In our use of computer process, will be exposed to a variety of data, there are document data, image data, video data, as well as chat QQ generated text data, with thunder download file data.
2. Classification of data
The data stored in the computer can be divided into two types: static data and Dynamic Data.
1> static data
L Concept: Static data refers to some permanent data that is generally stored on the hard disk. Hard disk storage space is generally relatively large, now ordinary computer hard disk has about 500G, so the hard disk can be stored in some relatively large files.
L Storage Duration: After the computer shuts down, the data is still in, as long as you do not actively delete or the hard drive is not bad, the data is always in.
What is static data: Static data is usually stored on the hard disk in the form of files, such as documents, photos, videos, etc.
2> Dynamic Data (temporary data)
L Concept: Dynamic Data refers to the temporary data that is generated dynamically during the process of running the program, which is generally stored in memory. Memory storage space is generally relatively small, now the average computer memory only about 4 G, so be careful to use memory, do not occupy too much memory space.
Storage Duration: After the computer shuts down, the temporary data will be erased.
What is Dynamic Data: When a program (software) is run, the entire program is loaded into memory, and during the run of the program, a variety of temporary data is generated that is stored in memory. When the program stops running or the computer is forced to shut down, all temporary data generated by the program will be erased.
You might ask, why not load all the applications into the hard drive, since the storage space is so large? One of the main reasons is that the memory accesses faster than the hard disk n times.
What data does the programmer care about the most?
3> conversion of static and dynamic Data
Static--Dynamic
dynamic-Static
3. Size of the data
1) both static and dynamic data are composed of 0 and 1. How do 0 and 1 make so much data?
2) data are size, static data will occupy the space of the hard disk, dynamic Data occupies memory space
3) The larger the data, the more the 0 and 1 are included, bits and bytes
4) 1 KB = b,1 MB = 1024x768 kb,1 GB = 1024x768 mb,1 TB = 1024x768 GB
Five, constant
1. What is a constant
Constant, which represents some fixed data
2. Classification of constants
1> integral type constant (int)
Includes all integers, such as 6, 27, 109, 256, 10, 0, 289, etc.
2> floating-point constant (float\double)
Floating-point constants are divided into double and float two data types
U double: double-precision floating point, in fact, is a decimal. such as 5.43, 2.3, 0.0 and so on (note that 0.0 is also a decimal)
U float: single-precision floating-point type, also a decimal, is less accurate than a double, meaning that it can represent a smaller number of decimal places. To differentiate from double, the float type data is terminated with F, such as 5.43f, -2.3f, 0.0f. It should be noted that there is absolutely no 10f in this format, the compiler will directly error, only decimals allowed to add F.
3> character constant (char)
You enclose a number (0~9), English letter (A~z, a~z), or other symbol (+ 、-、!、?, and so on) in single quotation marks, which makes up a character constant. such as ' 6 ', ' A ', ' F ', ' + ', ' $ ' and so on.
Note: The single quotation mark can only enclose 1 characters, and cannot be Chinese characters, the following wording is wrong: ' abc ', ' 123456 ', ' Male '
4> string Constants
U enclose one or more characters in double quotation marks (""), which makes up a string constant. such as "6", "Male", "wow haha", "ABCD", "MY_CAR4", in fact printf ("Hello World"); the statement "Hello World" is a string constant.
What is the difference between 6, ' 6 ' and ' 6 ' in usage? This is not to be discussed and will be introduced later.
Vi. variables
1. What is a variable
When the value of a data needs to change or be uncertain, it should be represented by a variable. such as game points.
2. Defining variables
1> Purpose
You must define any variable before it is used.
The purpose of defining variables is to allocate a chunk of memory to the variable to store the data later.
If you define more than one variable, you allocate different storage space for each variable.
2> format
Variable type variable name;
such as int num;
L variable name belongs to identifier
L Variable Type
U different types of variables occupy different sizes of storage space. Memory is extremely limited, allocating the appropriate storage space
The type of data stored by the U constraint variable (convenient operation)
3> instances
int main ()
{
int i;
char c;
int A, B;
return 0;
}
3. Use of variables
1> Assignment Value
L put something in the variable, it's assignment. With a semicolon after the assignment statement;
i = 10;
Note: The equals sign here is not "equal" in mathematics, but rather the assignment operator in C, which assigns the right constant 10 to the left variable i
L first assignment, which can be called "Initialize"
L Two types of initialization
U define first, then initialize: int A; A = 10;
The U-definition is initialized at the same time: int a = 10;
2> modification
L can modify the value of a variable and assign it multiple times. Each assignment will overwrite the original value
i = 10;
i = 20;
The last value of the variable i is 20
L use printf to output the value of one \ Multiple variables
int a = ten, c = 11;
printf ("a=%d, c=%d", A, c);
L Double\float\char output, some tips for formatting characters
Double height = 1.55;
char blood = ' A ';
printf ("height=%.2f, blood type is%c", height, blood);
L Simple Add-subtract operation
int a = 10 + 20;
Do not use when not initialized (the following wording is not recommended)
int score;
printf ("score=%d", score);
Transfer of values between 3> variables
L can assign the value of a variable to another variable
int a = 10;
int b = A;
L Continuous Assignment
A = b = 10;
4. Common errors
1> variable name is the same as int a = 10; int a = 12;
The scope of the 2> variable is not correct
Creation and release process of U variables
U code block scope {int a = 10;}
5. Exercises
1> swaps the value of an integer variable A, b. such as a=10, b=11; the value of a after Exchange is the value of 11,b is 10. Implemented in two ways:
U use third-party variables
int temp;
temp = A;
A = b;
b = temp;
U do not use third-party variables
A = b-a;
b = b-a;
A = B + A;
Solution:
#include <stdio.h>
/*
A = 10
b = 11
After Exchange
A-11
B-10
1. Use of third-party variables (work, mastery)
int temp = A;
A = b;
b = temp;
2. Do not use third-party variables (interviews, impressions)
A = b-a;
b = b-a;
A = B + A;
*/
int main ()
{
int a = 10;
int b = 11;
/*
int temp = A;
A = b;
b = temp;
*/
A = b-a;
b = b-a;
A = B + A;
printf ("a=%d, b=%d\n", A, b);
return 0;
}
Dark Horse Programmer--c Language some knowledge points summary