Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What are the common keywords in C language

2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/03 Report--

This article mainly shows you "what are the common keywords in C language". The content is easy to understand and clear. I hope it can help you solve your doubts. Let me lead you to study and learn the article "what are the common keywords in C language".

First of all, let's simply meet with these keywords (the highlighted keywords are to be introduced today)

There is a well-known data type: int,char,float,double.

There are also control statements used: if,for,do.

There are also some keywords that are mainly introduced today.

As for some new keywords, they are not mentioned in the above table. If you want to know about them, you can find them on your own.

Introduction of individual terms (can be skipped first, if you do not understand later, you can come back to understand)

Automatic variable: refers to the local scope variable, specifically, a kind of variable in which the system automatically allocates storage space for the control flow when it enters the variable scope and releases the space when it leaves the scope.

Storage class: is the standard of C language and C++ language, the accessibility (i.e. scope) and lifetime of variables and functions

Registers: registers are small storage areas used to store data within CPU, which are used to temporarily store the data and results involved in the operation.

The data in the computer can be stored in: register, cache, memory, hard disk, network disk.

(the above storage is sorted from left to right, the memory is getting larger, the fraud is getting lower and lower, and the transmission speed is getting slower and slower.)

1 、 auto

Auto: declare automatic variables, usually omitted

By default, variables declared within the code block are automatic variables, but the storage class can also be explicitly identified by the automatic variable keyword auto

The code is as follows:

The upper and lower variables of int are actually the same, except that the above two variables are omitted, such as autoauto int axiomatic 2 and register.

Register: declare register variables

After this keyword defines a variable, it asks the compiler to store the variable in the CPU internal register as much as possible, rather than accessing it through memory addressing to improve efficiency. (because the register is very small, if many register variables are defined, it may exceed the number of registers in CPU and exceed the capacity, so the variables may not necessarily be stored in the register)

3. Signed and unsigned

Signed: signed (generally defined constant defaults to signed)-can store positive and negative numbers

Unsigned: unsigned-cannot store negative numbers

Signed int axiom 10; / / generally defaults to signed, so just write as follows: int axiom 10; unsigned float=-75.3- > wrong definition float=-75.3- > correct definition signed float=-75.3- > correct definition 4, typedef

Typedef: type redefinition-generally for data types that are too complex, you can redefine a simple or identifiable use

Typedef

Unsigned long int axiom 10; / / the data type is too complex. You can use typedef to redefine typedef unsigned long int utensils intact intact int axiom 10; / / equivalent to unsigned long int axiom 10, extern

Extern: used before the declaration of a variable or function, to say that the variable / function is defined elsewhere and to refer to it here

By default, a global variable can only be used in the file in which it is defined (from defining the global variable to the end of the file in which it is located), but if the variable is declared as an external variable in another file, then the scope of this variable will be extended to another document.

The code is as follows:

First create a project named main.c in the source file

# inlcude extern int adextern int Add (int Xreint int y); int main () {printf ("% d\ n", a); printf ("% d\ n", Add (3jue 2));}

Then create a file named test.c- as the global variable, defined by the function in the source file.

Int axiom 10rampact / global variable int Add (int xreint y) / / {return xmapptomapacter / function definition}

The result will be output 10. 5.

6. Expansion

There are two cases in which variables are declared

One is the need to establish storage space. For example, int a has already established the storage space at the time of declaration.

The other is that there is no need to establish storage space, by using the extern keyword to declare the variable name without defining it.

For example: extern int a where the variable a can be defined in other files.

Extern int i; / / declaration, not definition

Int I; / / declaration, which is also a definition

Defines the allocated storage space, and declares that it will not

How to distinguish between a declaration and a variable

Extern tells the compiler that the variable is defined elsewhere

If the declaration has an initializer, it is treated as a definition, even if it is preceded by extern

The difference between the declaration and definition of a function is relatively simple, with {} is the definition, otherwise it is the declaration

Without the extern keyword, it is the definition of variables.

Static:

Static: declare static variables

Modify a local variable to make its life cycle longer (essentially changing the storage type of the variable)

Decorating global variables changes the scope of global variables so that static global variables can only be used within their own source files and can be used within other source files because global variables have external link properties. However, after being modified by static, it becomes an internal link attribute, and other source files cannot be linked to this static global variable.

The modifier function changes the link property of the function, changing the external link property of the function into an internal link property, so that the function can only be used within the source file where it is located.

Explain 1, the code is as follows:

# include void Add (int x) {static int aquifers 2; axioms; printf ("% d", xtropa);} int main () {int iTuno; for (iTunes)

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report