Take you to sneak a peek at the C language that cannot be bypassed by programming (1)


foreword

For the C language, compared to the first programming language that most people come into contact with, the C language has been around for decades and has been welcomed by all parties and widely used. It has a profound impact on the programming world. In the education field, it is usually used as the first programming language to learn, and it is used to cultivate beginners' programming thinking.
In this column, the knowledge of C will be systematically uploaded one after another. I hope it can help readers learn C language.


1. What is C language

C language is a process-oriented computer programming language, which is different from object-oriented programming languages ​​such as C++, C#, and Java. The design goal of the C language is to provide a programming language that can be compiled in an easy way, handle low-level memory, generate only a small amount of machine code, and can run without any operating environment support. C language describes problems faster than assembly language, with less workload, better readability, easy debugging, modification and transplantation, and the code quality is equivalent to assembly language. C language is generally only 10%-20% less efficient than the target program generated by assembly language code. Therefore, C language can write system software.
At the current stage, in the field of programming, C language is widely used. It takes into account the advantages of high-level language and assembly language, and has greater advantages than other programming languages. Computer system design and application programming are two major fields of C language application. At the same time, the C language has strong universality and can be applied in many computer operating systems with remarkable efficiency.
C language has a complete theoretical system with a long history of development, and plays a pivotal role in programming languages.

2. Data type

There are various data types in C language: char, short, int, long, long long, float, double, etc. They also have sizes and take up space, and they vary in size. Here it is shown to you in the form of code.

insert image description here
insert image description here

3. Variables and constants

3.1 How to define variables

int age = 20;
float height = 170.0f;
char ch = ‘a’;

3.2 Variable naming rules

  • Only letters, underscores, numbers
  • cannot start with a number
  • Variable names cannot use keywords (because they will conflict with keywords in the compiler)

3.3 Differentiation of variables

There are global variables and local variables for variables. Here we need to keep in mind:
when the local and global variables have the same name, the local variable is used first. The
above code:
the first a is a global variable, and the second a is a local variable
insert image description here

3.4 The scope and life cycle of variables

Scope
The scope of a local variable is the local scope where the variable is located. That is to say, the variable will be destroyed and cannot be used if this scope is specified. The
scope of the global variable is the entire project, which can be used anywhere. The
above code:
insert image description here
life cycle
local variable Life cycle: Entering the scope begins and exiting the scope ends.
Life cycle of global variables: the life cycle of the entire program.
Supplement:
The essence of variable creation is to open up a space in memory to store data.
Destruction means that this variable is no longer needed, and its space is returned to the operating system.

3.5 Constants

C language is divided into the following types of constants:
literal constants
const modified constant variables (that is, the variables it modifies cannot be changed again)
#define defined identifier constants
enumeration constants
insert image description here
Note: const modified constant variables are only in the c language cannot be modified in the grammar, but can be changed in C++

4. Strings and transition characters and comments

4.1 Strings

insert image description here
This kind of string enclosed by double quotes is called a string.
Note: the end mark of the string is an escape character of \0. When finding the length of the string, it also encounters the end of \0, and \0 is not counted as content.
There are two representation methods for strings. We observe the difference between these two methods through debugging.
We can find that there are some strange things in arr2 printed out. Why is this? At this time, when we observe the monitoring window, arr2 lacks a \ 0, from this we know that it is because there is no \0 in arr2, when printing arr2, it can only stop when it finds \0, so there are those strange things
insert image description here

insert image description here

4.2 Escape characters

Explain that \ddd and \xdd
ddd represent 3 octal numbers, such as \130 means X
xdd means 2 hexadecimal numbers, such as \x30 means 0
insert image description here

4.2 Notes

Comments are generally to add some explanations to the code or comment some unnecessary codes.
There are two ways to comment.
The first is double /, and the second is /* */. Generally, the first is used, and the second cannot be nested. , the effect is not very good
insert image description here
insert image description here


To be continued...

Guess you like

Origin blog.csdn.net/paperjie/article/details/130015953