Basic structure of **C language program * *
"' C
#include <stdio.h>//#include pre-processing instructions
void Main ()
{
printf ("Hello world!\n");
}
```
-preprocessor directives are not required, if any, at the beginning of the program
-Files ending with. h are header files
-stadio.h file contains functions for input and output statements
-The main () function is the starting point for C language Program processing
-The main () function can return a value, or it can not be returned. When there is no return value, the previous keyword is viod
-printf Print command to print "" contents on screen
-\ n line break
* * NOTE * *
-Single comment//
Multiline Comment/* */
Compilation and execution of **c languages * *
-Compile: Form the target code/file. The target code is the result of the compiler's output, and the common extension is ". O" or ". obj"
-Connect: Connect the target code to the C function library and merge the library code used by the source program with the target code to form the final executable binary machine code (executables)
-Execute: Run C application in a specific machine environment
**c language variable naming rules * *
-can only consist of 3 characters of letters, numbers and underscores, and the first character must be a letter or an underscore;
-the variable name cannot contain any special characters except _, such as%, #, comma, space, etc.;
-Reserved words cannot be used.
**c language Basic Data type * *
-numeric types, including shaping (int, short, long), floating-point (float, double).
-character type, including Char.
-Other types, including construction type, pointer type, empty type, etc.
**c language Common Data type * *
Data type type specifier number of digits value range
Data type |
Type descriptor |
Number of digits |
Range of values |
Integral type |
Int |
32 |
-2147483648 ~ +2147483647 |
Short-integer |
Short |
16 |
-32767 ~ +32768 |
Long integer type |
Long int |
32 |
-2147483648 ~ +2147483647 |
Single-precision floating-point type |
Float |
32 |
-3.4E-38 ~ +3.4E+38 |
Double-precision floating-point type |
Double |
64 |
1.7E-308 ~ 1.7E308 |
Character type |
Char |
8 |
-128 ~ +127 |
* * declaring and using variables * *
-Declare only variables: data type variable name;
-Initialization at declaration: Data type variable name = value;
-declaration of variables after initialization: data type variable name; Variable name = value;
= the value assigned to the preceding variable
* * Common ASCLL Code * *
-0: null characters
-32: Space
-65~69:a~z
-97~122:a~z
**printf functions and conversion characters * *
-%d: Signed decimal integer
-%c: Single character
-%s: string
-%f: Floating-point number, the default precision to 6 decimal places, can be used to%.xf accurate to the decimal point after the X-bit
-percent percent: print a semicolon
* * Escape Sequence * *
-\a Beep Alarm
-\ nthe line cursor moves to the beginning of the next row
-\ t Horizontal tab moves the cursor to the next horizontal tab position
**scanf function * *
SCANF can read data in different formats
Usage:
"' C
int num;
printf ("Please enter quantity:");
scanf ("%d", &num); & Escape Symbols
```
* * Convert strings and Meanings * *
-%d: Interpret the input as a signed integer
-%c: Interpret the input as a character type
-%s: Interpret the input as a string
-%f: Interpret the input as a single-precision floating-point number
-%LF: Interpret the input as a double-precision floating-point number
* * Arithmetic operator * *
-Unary Operator: + + 、--
-Two-dollar operator: + 、-、 *,/,%
* * Front + + and rear ++**
-i++ is first to take I value to do the calculation, the operation finished last again +1;
-++i is the first +1, then the I value to do the calculation.
* * Automatic type conversion * *
Converts a value of a type that represents a small range to a value of a type that represents a large range
Double result = 5/2; 5 and 2 are plastic First Division, the result is 2
When a value of 2 is assigned to the result of a double type, it is automatically converted to double type 2.0
* * Forced type conversion * *
(type name) variable or numeric value
20171129 C language Knowledge point carding