C Language Learning (II.)--Data type

Source: Internet
Author: User

    • Basic data types
The basic data types for C are: integer, character, single-precision floating-point, double-precision floating-point.
Category Type name Data length
Character Char 8 Guests
Short-integer short int, unsigned short int 16 Guests
Integral type
int, unsigned int 32 Guests
Long integer type long int, unsigned long int 32 Guests
Single-precision floating-point type Float 32 Guests
Double-precision floating-point type Double 64 guests
 
    • Enum type
An enumeration type is a type whose value is a symbolic constant rather than a literal.        Declaration form: enum Door_type {OPEN, CLOSE};        The above statement declares a type called Door_type, and this type of variable can be declared as follows: Enum Door_type First_door, second Door;        You can specify a specific integer value for the symbol name of an enumeration type: enum Door_type {OPEN = 1, CLOSE = 8}; As shown above is a value that specifies the symbol name, if not specified by default starting from 0, each symbol is 1 larger than the previous one.
    • Pointer
If you declare a variable in your program and use the address as the value of the variable, then this variable is a pointer variable.        Define pointer variables to use the pointer declarator *.        The general format for defining pointer variables is: type name * pointer variable name; int *p;
    • Variable declaration
The general form of a variable definition is: A type name variable table; int A, b, C; A variable table can have a variable name or multiple variable names separated by commas.
    • Constant
Constants look exactly like variables, except that their values cannot be modified. int const A;
    • Global variables and local variables
Variables declared outside of a block of code are always stored in static memory, which is called a global variable. The role of global variables is then from the declaration to the end of the file. Global variables are created before the program runs, and persist throughout the execution of the program. If the specified initial value is not displayed, it is initialized to 0.        If you add a static property to a global variable, you do not allow other source files to access the variable. Variables declared within a code block are typically stored on the stack, called local variables. The scope of a local variable is within a code block. A local variable is created when the program executes into a code block of a variable declaration, and the variable destroys itself when the program leaves the code block. Local variables do not have a default initial value, so it is best to give the initial value to the local variable display. If you add a static property to a local variable, the variable is not stored on the stack, its value remains in the entire execution period of the program, but its scope remains the whole block of code.

C Language Learning (II.)--Data type

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.