Initial C language -- the foundation of programming for all things in C

Article catalogue


Once I entered the editing process, it was as deep as the sea. From then on, long hair was a passer-by
OK, stop, not much BB. Let's start with the initial C language. You watchers should keep your hair!

1, What is C language?

C language is a language Process oriented of Abstraction General programming language, widely used in Bottom development . C language can be written in a simple way compile . low level processing storage . C language produces only a small amount of machine language And don't need any Operating environment Support an efficient programming language that can run. Although C language provides many low-level processing function , but it still remains Cross platform C language programs written in a standard specification can include similar features Embedded processor as well as Supercomputer And many other operating platforms Computer platform Proceed on compile.

2, The first C language program

Welcome to the world of programming, petite little princess (Prince)!

#include <stdio.h>
int main()
    printf("hello world\n");
    return 0; 
//The main function is the entry of the program
//There is only one main function in a project

II. Data type

Mastering data types is a necessary way to learn C language.

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
#include <stdio.h>
int main()
    printf("%d\n", sizeof(char));
    return 0; 
//By analogy, you can try other data types
//In programming software, sizeof (long) > = sizeof (int)
//sizeof() is a memory capacity measurement function that returns the size of a variable or type (in bytes); In C language, sizeof() is an operator to judge the data type or expression length. You can try it on the computer.
There are so many types in C language, in fact, in order to enrich the expression of various values in life.
char ch = 'w';
int  long= 120;
float width = 200f;

III. constants and variables

3.1 interpretation of terms

Some values in life are constant (such as pi, gender, ID number, blood type, etc.) - variables.

Some values are variable (e.g. age, weight, salary) - variables

3.1} classification of variables (local variables and all variables)

The following is a brief code introduction

#include <stdio.h>
int A = 2019;//global variable
int main()
    int B = 2018;//local variable
    int A = 2020;//local variable
    printf("A = %d\n", A);
    return 0; 
//There is no problem with the definition of local variable A above!
//When local variables and global variables appear at the same time, local variables are used first

3.2 scope and life cycle of variables


scope is a programming concept. Generally speaking, the names used in a piece of program code are not always valid / available
The scope of the code that limits the availability of the name is the scope of the name.
1. The scope of a local variable is the local scope of the variable.
2. The scope of global variables 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
1. The life cycle of a local variable is the beginning of the scope life cycle and the end of the scope life cycle.
2. The life cycle of global variables is the life cycle of the whole program.

3.3 constants

Constants in C language are divided into the following types:
Literal constant
const modified constant
#define defined identifier constant
Enumeration constant
#include <stdio.h>
//give an example
//Ale, female and secret in parentheses are enumeration constants
enum Sex
 MALE,   // 0
 FEMALE, // 1
 SECRET  // 2
//Note: enumeration constants start from 0 by default and increase by 1 in turn

int main()
    //Literal constant presentation
    3.14159;//Literal constant
    2000;//Literal constant
    //const modified constant
    const float Pai = 3.14f;   //Pai here is a constant variable modified by const
    Pai = 6.33;//It cannot be modified directly!
    //#Demonstration of identifier constant of define
 #define MAX 100
    printf("max = %d\n", MAX);
    //Enumeration constant demo
    printf("%d\n", MALE);
    printf("%d\n", FEMALE);
    printf("%d\n", SECRET);
    return 0;
The PAI in the above example is called const modified constant variable. Const modified constant variable in C language only limits the variable pai at the grammatical level and cannot be changed directly, but Pai is essentially a variable, so it is called constant variable


Leave a message/comment before it becomes a top/hot tweet.

Keywords: C C++ Programming

Added by wpsa on Thu, 10 Mar 2022 07:01:14 +0200