2020-12-01

Getting to know the C language

1. The first C language program
"Hello World"
-a c program is composed of several header files and functions
-the main function is the program entry
-there is one and only one main function in a project
2. Data type (basic)
1. Whole type

  • int integer
  • short
  • long long integer (long long longer integer)
  • char character data type (also integer)
    2. Floating point type
  • float single precision floating point
  • double double-precision floating-point type
    On a 32-bit system: int 4 bytes, short 2 bytes, long 4 bytes, float 4 bytes, double 8 bytes, char 1 byte
    3. Variables and naming rules
    1. 3. Elements: variable name space address
    2. Naming rules:
    ①Intuitively readable and understandable
    ②The length should be appropriate (the vowel can be removed to form an abbreviation for particularly long ones)
    ③When the identifier is composed of multiple words, the first of each word One letter is uppercase, the rest is lowercase④Variable
    /function common naming style:
  • Little hump nomenclature: toGuess
    the first letter of the first word in lowercase, the first letter of subsequent words in uppercase
  • Big hump nomenclature:
    the first letter of each word in ToGuess is capitalized.
  • Serpentine nomenclature:
    use _ to divide between to_ guess words, and use lowercase letters uniformly.
  • Spine nomenclature:
    Use segmentation between to-guess words, and use lowercase letters uniformly.
  • Hungarian nomenclature: The
    first letter of iToGuess is an abbreviation for the type. i means int, s means string, C means character...
    [Snake-shaped nomenclature in C/C++ is also common (also widely used) Other Camel case nomenclature is the most common in the scene]
    ⑤Initialization
    3. Classification
    Local variables and global variables
    Insert picture description here
    Differences:
    ①Scope
  • Local variable scope: the local scope of the variable
  • Global variable scope: the entire project
    ② life cycle
  • Local variable life cycle: the beginning of the scope of entry, the end of the scope
  • Global variable life cycle: the life cycle of the entire program
  • Insert picture description here
    Four, constants (cannot be modified ie constants)
    1. Literal constants
    2. Constant variables modified by const (const can be placed before and after int)
    3. Identifier constants defined by #define (#define Max 100)
    4. Enumeration constants (It is a set of plastic shaping)
    Insert picture description here5. Input and output statements
    1. Character data input and output
    Character output putchar (int c);
    character input getchar (void);
    2. Format input and output
    format output printf ("format control string", output List);
    format input scanf ("format control string", address list);
    3. string input and output
    string output puts(const char *str);
    string input gets(char *str);

Six, string

  1. In C, use "" to lead to 2.
    C language has no string type but character type
  2. "/0" is the end sign
    4. The difference between sizeof and strlen
    ①sizeof is an operator, not a function, used to find the size of the string, and the result of executing sizeof is determined during compilation, so \0
    is included. ②strlen is a function and not an operator. The result is determined when the program is executed, so stlen does not include \0
    . Seven. Escape characters
    Insert picture description here
    8. Comments
    /* */cannot be nested (C style)
    generally used // Comments (C++ style)
    support multiple comments to help you understand the code
    if(0) (equivalent to comment) if(1) is also allowed but generally not used.
    9. Select statement
    Simple if else statement
    Insert picture description here
    Nested if else statement
    Insert picture description here
    10. Loop statement 1. For
    loop
    for (①; ②; ③ ) { Code block; } Note separated by semicolons. Statements are enclosed by {} ① Variables are initialized only once ② Loop control, if true, enter the loop, if false, end the loop ③ Execute after ②, then continue to execute ② 2.while Loop while (loop condition, true loop, false end loop) { code block; (continue to loop after execution) } 3. do while loop do{ code block;















    }while(n);n is a conditional expression.
    Note that there is a semicolon
    after while. Because there is no variable initialization, directly enter the loop and then judge, so the loop should be performed at least once.
    10. Function (also called subroutine)
    1. Function is one that can be repeated Use code snippets to avoid duplicate code being copied repeatedly, making the code more concise and easier to understand
    2. General classification
    ①standard library function
    ②third-party library function
    ③custom function

①The default return value of the C function is plastic, but it is absolutely not allowed to ignore the return value type.
②The function can only run when it is called, and all internal temporary variables do not exist.
③When the function is called, if the parameter is passed, the function is called To form a copy of the parameters
4. A function can be called multiple times, and different parameters can be passed in each call. In a project, the function definition can only exist once, but the function declaration can have many times. The function declaration is generally placed in the call The first of the position
XI. Array
1. Definition 2. In
Insert picture description here
C, if the array is used as a function parameter, it will be implicitly converted into a pointer variable

Guess you like

Origin blog.csdn.net/WSXHN/article/details/110420645