First, knowledge of C language
1.1The origin of C language
In 1972, Bell Labs Dennis, Ricky and Ken, Thompson the C language when developing the UNIX operating system, however, C was not entirely a whim of Ricky, he was designed on a B-language basis, and the origin of B was another story, The purpose of C language design is to use it as a programming tool for programmers, so its main goal is to become a useful language.
advantages and disadvantages of 1.2 C language
Advantages:
1. Design features: C language programming easier to understand, more reliable.
2. High efficiency: C program is more compact, and the speed of operation is fast
3. Portability: In a system C program slightly modified, or do not modify it can be run in other systems.
4. Strong flexibility: Many compilers and interpreters are written in C (FORTRAN, Perl, Python, basiac ...). )。
5. For programmers: C language is designed to meet the needs of programmers, programmers can access the hardware through C, manipulating in-memory bits
Cons:the C language uses pointers, while programming errors involving pointers are often difficult to detect.
Ii. Overview of the C language2.1 Simple C program examples
1#include <stdio.h>2 3 voidMain ()4 {5 intnum;6num =1;7 8printf"I-a simple");9printf"coputer.\n");Tenprintf"My favorite number is%d because it is the first number\n"); One}
The results of the operation are as follows:
Note : How do I comment?
Single-line Comment://
Multiline Comment:/* Comment content */
2.2 variable naming
can be named with lowercase letters, uppercase letters, numbers, and underscores (_), and the first character of a name must be a letter or an underscore cannot be a number
2.3 Further use of C
1#include <stdio.h>2 3 voidMain ()4 {5 intfeet, fathoms;6 7Fathoms =2;8Feet =6*fathoms;9printf"there is%d feet in%d fathoms!\n", feet, fathoms);Tenprintf"Yes, I said%d feet!\n", feet); One}
The results of the operation are as follows:
iii. data and C3.1 Program Examples
1#include <stdio.h>2 3 voidMain ()4 {5 floatweight;6 floatvalue;7 8printf"is worth your weight in platinum?\n");9printf"Let ' s check it out.\n");Tenprintf"Please enter your weight in pounds:"); Onescanf"%f",&weight); AValue =1700.0* Weight *14.5833; -printf"Your weight in platinum is worth $%.2f.\n", value); -printf"You are easily worth that! If Platinum Prices drop,\n"); theprintf"eat to maintain your value.\n"); -}
Operation Result:
C Language Learning 1