C variable and function storage type

Source: Internet
Author: User

I. Variable declaration format:

Storage Type modifier data type variable name; 2. function declaration format: storage type return type function name (parameter list) {} Storage types: 1. Auto : Only the storage type of [variable] can be identified. Identifies the local variable stored in the running process [stack region]. Note: If a local variable is directly involved in calculation without initialization, the system will assign a random value to it. Extern : Identifies both variables and functions. For variables, extern is used to declare the global variables referenced (used) in the current file and defined in other files in the current project. Only allocate memory space once. If the global variable is not initialized, the initial value 0 is automatically assigned to it during compilation. there are two ways to use it: (1): The global variable is defined in the header file, you need to use the variable file to include the corresponding header file. Then, use the global variable directly in the source file. (2) If the global variable is defined in another file (*. c), use the extern declaration in the current file (the source file that references the global variable. For a function, extern only identifies the function scope. The default storage method is extern. In other words, if a function's storage type is not declared in a project, the function can be referenced by all files in the current project. 3. Register : It can only be used to identify variables, and the types of variables can only be integer and complex. This keyword is mainly used to identify variables that are used for a long time. If you declare a variable as register, it is recommended that the compiler resident its variable in the CPU register. Uninitialized register variables are randomly assigned a value. 4. Static : Static. Variables or functions can be identified. Declared static variables (global variables or local variables) are stored in the data zone, and their life cycle is the entire Program Runtime. If it is a static local variable, its scope is inside a pair of {}; if it is a static global variable, its scope is the current file. If the static variable is not initialized, it will be automatically initialized to 0. The static variable will only be initialized once. 5. String constant: it is stored in the data zone and its life cycle is the entire program running period. Char * A = "Hello world! ";

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.