Regain the data of C

Source: Internet
Author: User
Tags float double function prototype

There are only four data types in C, integer, float, pointer, and aggregation type

One. Integral type

Characters, short integer, Long shape, integer

The standard does not stipulate that the long shape is longer than the short integer, stipulating that the long shape should be at least as long as the integral type, and the integral type should be at least as long as the short integral type

short int at least 16 bits, long int at least 32 bits, and the default number of INTs is determined by the machine's environment word length. The value of a char variable is best limited to the intersection of unsigned char and signed char, and it is best not to participate in arithmetic operations, given compatibility issues

Integer literals: Variables declared with const, when an integer literal is present in a program, it belongs to the type having the last character of the literal value, L is long, U is unsigned type, and the type of character constant is always int, you can't add another suffix in the back

Enum type

An enumeration type refers to a type whose value is a symbolic constant rather than a literal; for example, enum Jar_type {Cup,pint,quart,half_gallon,gallon}

This statement declares a type, called Jar_type, that declares a variable of this type as follows

Enum Jar_type Millk_type,gass_can,medicine_bottle;

These types of variables are actually stored as integers, and the actual values of these symbol names are integral types, and you can set specific integer values for these symbol names

Enum jar_type{cup=8,pint=16,quart=32,half_gallon=64,gallon=128};

Do not mix integral types with enumeration values

Two. Floating point Type

Float double long double consisting of their length specified and Int,short int, long int close

Three. Pointer

There is no pointer constant in C, if you need to modify the string, store it with an array you can assign a string constant to a pointer to a character, but you cannot assign a string constant to a character array, because the direct value of the string constant is a pointer, not the characters themselves

Declaration pointer: int *b,*c,*d; is the correct way to declare three pointers

Four. typedef

A typedef declaration is basically the same as a common declaration, but a typedef is a keyword that appears in front of the declaration

Char *ptr_to_char;   change typedef char *PTR_TO_CHAR; Ptr_to_char A; Declaring A is a pointer to a character

New types should be created with typedef instead of # define

Five. Constant

Use the CONST keyword to declare constants whose values cannot be modified

How to initialize 1. Initialize the int const a=150 at the time of Declaration; 2. A parameter declared as const in a function gets the value of the argument when the function is called

When it comes to pointer variables, the situation becomes interesting.

Int *pi;

int const *PCI; is a pointer to an integer constant, you can modify the value of the pointer, but you cannot modify the value it points to

int * const CPCI; is a constant pointer to an integral type, the pointer is a constant, its value cannot be modified, but you can modify the value of the integral type it points to

#define指令时另一种创建名字常量的机制 can be used wherever a character-value constant is allowed, such as declaring the length of an array, whereas a const can only be used where the variable is allowed

Six. Scope

1. code block scope (all statements that lie between a pair of curly braces are called a block of code)

2. File scope

Any identifier declared outside of all blocks of code has a file scope and is accessible from the beginning of the declaration to the end of its source file, and the function name defined in the file also has a file scope

3. Prototype scope

Only applies to the parameter names declared in the function prototype, in the prototype (that is, at the time of Declaration), the name of the parameter is not required, can be random, do not need to be consistent with the parameter name at the time of definition

Seven. Link

Three kinds: external,internal,none

The default property for the outside of the code block and the function is external, while the default within the code block is the none type

None is always treated as a separate entity, that is, multiple declarations of the identifier are treated as separate entities, and the identifier of the internal points to the same entity in all declarations within the same source file, regardless of how many times the external identifier is declared, in several source files representing the same entity

The static keyword can change the external link property to the internal property, and only the declaration with the default link property of external will work

extern keyword, if you know the specified external link property for an identifier, you can access the entity defined in another location

Eight.. Storage type

There are three places you can use to store variables: normal memory, runtime stack, hardware register

Auto,static,register

Try not to use register, because the compiler does not necessarily ignore, in some computers, the most frequently used variables can be declared as register variables, can improve program efficiency

When the default type of a variable declared inside a code block is auto, it is said to be stored in the stack, and the default storage type of a variable declared outside of the code block is the static type, which is created before the program runs, always exists throughout the execution of the program, and always maintains the value of the prototype. Unless you assign him a different value, or it's the end of the program.

A function's formal parameter cannot be declared static because the argument is always passed to the function on the stack, used to support recursion, a variable declared inside a code block, and a static local variable if you add the static keyword to it.

Initialize: Static variables, the system will automatically assign them, and the dynamic will not, if not give him explicit initialization, their values are always garbage

  

Regain the data of C

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.