<>1. What is? C language

C Language is a general computer programming language , Widely used in underlying development .C The design goal of the language is to provide a way to compile in a simple way , Processing low-level memory , Generate a small amount of machine code and a programming language that can run without any running environment support .
<>2. first C Language program
#include <stdio.h>// Header file int main() { printf("hello bit\n"); return 0; }
//main Function is the entrance of the program // In a program main Function has one and only one //printf Function is a formatted output function , yes C Language standard library function , Defined in header file
<>3. data type

(1) type
char // Character data type short // Short int // plastic long // Long integer long long // Longer shaping float // Single-precision floating-point
double // Double precision floating point number .....
(2) Calculate the size of each type : use sizeof function .sizeof() Is a memory capacity measurement function , The function is to return the size of a variable or type ( In bytes )
#include <stdio.h> int main() { printf("%d\n", sizeof(char)); printf("%d\n",
sizeof(short)); printf("%d\n", sizeof(int)); printf("%d\n", sizeof(long));
printf("%d\n", sizeof(long long)); printf("%d\n", sizeof(float)); printf("%d\n",
sizeof(double)); printf("%d\n", sizeof(long double)); return 0; }
<>4. variable , constant

Some values in life are constant ( such as : PI , Gender , ID card No. , Blood type, etc )
Some values are variable ( such as : Age , weight , salary ).
Constant value ,C The concept of constant is used in language ; Become value C Language is represented by variables .

(1) Method of defining variables
int age = 45; float weight = 50.2f; char ch = 'x';
(2). Classification of variables

a. local variable b. global variable
#include <stdio.h> int global = 2019;// global variable int main() { int local = 2020;
// local variable int global = 2021;// local variable printf("global = %d\n", global); return 0; }
// The result is global=2021 * When a local variable and a global variable have the same name , Local variable priority .
(3) Use of variables
#include <stdio.h> int main() { int num1 = 0; int num2 = 0; int sum = 0; printf
(" Enter two operands :"); scanf("%d%d", &num1, &num2); sum = num1 + num2; printf("sum =
%d\n", sum); return 0; } //num1,num2,sum All variables //scanf Is input ,printf Is output
(4) Scope and lifecycle of variables
① Scope
Generally speaking , The names used in a piece of code are not always valid , The scope of the code that limits the availability of the name is the scope of the name
a. The scope of a local variable is the local scope of the variable
b. The scope of the global variable is the whole project
② life cycle
The life cycle of a variable refers to the period between the creation of a variable and its destruction
a. The life cycle of a local variable is the beginning of the scope life cycle , Out of scope lifecycle end
b. The life cycle of global variables is the life cycle of the whole program
(5). constant
* Literal constant
*const Modified constant
*# define Defined identifier constant
* enumeration constant
#include <stdio.h> enum Sex { MALE,//0 FEMALE,//1 SECRET//2 };
// In parentheses MALE,FEMALE, SECRET Are enumeration constants // The default value of enumeration constant is from 0 start , Increase down in turn 1 // be careful , There is no following the last constant ( ,) number int
main() { // Literal constant presentation 3.1415;// Literal constant 1500;// Literal constant //const Modified constants cannot be modified directly ! const float
pai= 3.14f; // there pai yes const Modified constant pai = 5.14;// It cannot be modified directly ! Still 3.14f
//#define Identifier constant for demonstration #define MAX 100 printf("max = %d\n", MAX); // Enumeration constant demo printf(
"%d\n", MALE); printf("%d\n", FEMALE); printf("%d\n", SECRET);
const Modified constant in C In language, variables are limited only at the grammatical level pai Cannot be changed directly , however pai It is essentially a variable , So it's called a constant variable .

<>5. character string , Escape character , notes

(1). character string
By double quotation marks (Double Quote) A string of characters that is drawn together is called a string literal (String Literal), Or abbreviated string . Its end sign is \0
"hello world.\n"// It's just a string
\0 Calculating string length ( as strlen function ) It's time for the end sign , Do not do string content .
"hello.\n"// The storage content is {'h','e','l','l','o','\0'} So the length is 5 #include <stdio.h>
// The following code , What is the print result ? Why? ?( prominent '\0' Importance of ) int main() { char arr1[] = "bit";
// The complete string system will add itself at the end \0 char arr2[] = {'b', 'i', 't'};// No, \0 char arr3[] = {'b',
'i', 't', '\0'};// Add manually \0 printf("%s\n", arr1); printf("%s\n", arr2); printf(
"%s\n", arr3); return 0; }
(2). escape sequence
Escape character interpretation \? Used when writing consecutive question marks , Prevent them from being parsed into three letter words \' Constant used to represent characters ' \“ Double quotation marks used to represent the inside of a string \\
Used to indicate a backslash , Prevent it from being interpreted as an escape sequence character . \a Warning character , Beep \b Backspace character \f Feed character \n Line feed \r enter \t Horizontal tab \v
vertical tab \ddd ddd express 1~3 An octal number . as : \130 X \xdd dd express 2 Hexadecimal digits . as : \x30
for example
#include <stdio.h> int main() { printf("%c\n", '\'');// Output as ‘ ’ printf("%s\n",
"\"");// Output as “ ” return 0; }
(3) notes
Unnecessary codes in the code can be deleted directly , You can also comment it out . Some codes are difficult to understand , You can add annotation text
#include <stdio.h> int Add(int x, int y) { return x+y; } /*C Language style notes , Comments cannot be nested int
Sub(int x, int y) { return x-y; } */ int main() { //C++ Comment Style , One or more lines can be annotated //int a =
10; // call Add function , Complete addition printf("%d\n", Add(1, 2)); return 0; }
<>6. Select statement
if( expression ) // If the expression is satisfied , Just execute the statement 1 { sentence 1; } else // Otherwise, execute the statement 2 { sentence 2 }
<>7. Circular statement

(1)while loop
while( expression ) { sentence 1; } // When the expression holds , Keep executing statements 1.
Code demonstration
#include <stdio.h> int main() { int i = 0; while(i<5) { i++; printf("hello\n");
} return 0; } // The running result is printed 5 that 's ok hello code
(2)for loop
for( initialize variable ; Cycle condition ; Variable change )// Separated by semicolons { Intermediate circulatory body ; } // All expressions can be omitted , But a semicolon is not allowed
Code demonstration
#include <stdio.h> int main() { int i=0; for(i=0;i<5;i++) { printf("hello\n");
} return 0; } // The running result is printed 5 that 's ok hello code
(3).do…while loop
do { Circulatory body ; }while( Cycle condition ); // Means : do ... until ( End if conditions are not met )
Code demonstration
#include <stdio.h> int main() { int i=0; do { printf("hello\n"); i++; }while(i<
5); return 0; } // The running result is printed 5 that 's ok hello code

Daily Recommendation