The first two things about learning C language

1. Basic elements of C language

       The development of programming language is inseparable from natural language, so the grammar and vocabulary of programming language are also developed from natural language, and the basis of natural language is text. For example: if you want to learn Chinese, you must first learn Chinese characters. To learn English, you must first learn words. You can see from the figure below that if you want to learn C language, you must first learn keywords.

 So what are the keywords of the C language? We can look up the keywords column of the official document of the c99 version of the C language

From the official documents, we can see that there are 37 keywords we need to master, and 32 of them are commonly used , and we will learn about those specifically. There are few keywords to remember, and many keywords are abbreviations of words.

Two, the data type of C language

 1. Data concept:

     People use computers to process massive amounts of data, but there are various types of data, including sounds, images, text, and numbers, so how should the computer distinguish the data? The result is that the computer does not need to distinguish, and the computer only recognizes binary.

2. The concept of memory:

    A computer is composed of five parts, namely memory, arithmetic unit, controller, input device, and output device.

    The working principle of the computer is actually not complicated, and the process is roughly as follows: the user inputs data into the memory of the computer through the input device (keyboard), and then the controller reads the data from the memory address, and then sends it to the calculator for calculation, and then The controller reads the data from the arithmetic unit, finds the corresponding memory address, stores the data, and then uses the output device (display) to feed back the data to the user.

For the memory in the computer, it is generally divided into two types: RAM (random access memory) and ROM (read-only memory) 

3. Memory unit

   A MOS tube in the memory can store a binary number 0 or 1. For the convenience of memory, the standard stipulates that a binary number is represented by bit. Bit (bit) is the abbreviation of binary digit, which is translated into bit in Chinese . Technical terms generally refer to a binary number as a one-bit binary number. So bit is used to represent the smallest unit of computer data

3. Constant variables in C language

      The memory is a continuous space, and each storage unit (8 bit) in the memory has a corresponding number, and this number is a fixed number. The number of the storage unit is usually called the address of the storage unit, and the user can directly perform read and write access to the storage unit according to the address of the storage unit. However, under normal circumstances, users will not directly access based on the address, because the access efficiency is too low.

                                    

   The user can name the storage unit provided by the linux kernel, and then the linux kernel will establish a mapping relationship between the user's naming and the address of the storage unit, so that the user can access the storage unit through the name of the storage unit.

  1. constant variable

     The C language standard stipulates that the user has the right to apply for a storage unit from the memory, and the user can name the storage unit, and the user is required to indicate the size of the storage unit (unit is calculated in bytes) in advance, so that the Linux kernel will start from Find a suitable space in the memory, and feedback the address of this space to the user.

1. Constant

 The constant refers to the quantity whose value will not change during the running of the program . Generally used numbers, such as 3.14, are used to represent the pi. In general, users use the macro definition to realize the design of the constant. The macro definition is actually It is a simple text replacement. In the preprocessing stage, the preprocessor will expand the macro definition in the program. The C language stipulates that the macro definition is  designed using the preprocessing instruction #define .

2. Variables

A variable refers to the amount whose value may change during the running of the program . The user can apply for a storage unit from the kernel according to actual needs, and name the storage unit, and then the user can modify the data in the storage unit at any time. The size of the requested storage unit can be specified by the data type in C language.

3. Naming rules

    Variables and constants are also called identifiers , and the naming of identifiers must follow the rules: identifiers are composed of letters, numbers, and underscores, and the first character of an identifier can only be a letter or an underscore.

   Note: In order to prevent ambiguity , the C language standard stipulates that system reserved words, function names that already exist in the program, and identifier names that have been defined by users cannot be used as new identifier names.

C language provides some basic data types to represent the width of the data. Commonly used basic data types are as follows:

 The usage of the type is introduced next time

Guess you like

Origin blog.csdn.net/yangjiaying1/article/details/130068456