Current location - Plastic Surgery and Aesthetics Network - Plastic surgery and beauty - Transformation of Integer Constants in C Language
Transformation of Integer Constants in C Language
First of all, what do constants in C language express? We can understand what its problem is:

Constant: a quantity whose value will not change, called a constant. They can be classified in combination with data types. For example: integer constants, floating-point constants, character constants, etc. Constants can be directly referenced without definition and initialization.

Classification of constants: Constants are divided into direct constants and symbolic constants.

Direct constants are also called literal constants. Such as 12, 0, 4.6,' a',' abcd'

Symbolic constants: defined by macros: #define

circumference ratio

3. 14

Features: the value of a constant will not change within its scope, and it can no longer be assigned. It is used as an immediate number when it appears. In other words, it can only be accessed and read, but not written and distributed.

A read-only attribute is added to the memory space where the constant is located, which is somewhat similar to the const keyword, so its common problems are as follows:

(1) can define const constant, which is immutable.

For example:

constant

Internationalorganizations (same as international organizations)

max = 100;

Internationalorganizations (same as international organizations)

array[max];

(2) It is convenient for type checking, so that the compiler can better understand the processing content and eliminate some hidden dangers. For example:

empty

F (constant

Internationalorganizations (same as international organizations)

I)

{

.........}

//The compiler will know that I is a constant and cannot be modified;

(3) Ambiguous numbers can be avoided, and it is also convenient to adjust and modify parameters.

(4) It can protect the modified things, prevent accidental modification, and enhance the robustness of the program.

Still in the above example, if I is modified in the function body, the compiler will report an error;

For example:

empty

F (constant

Internationalorganizations (same as international organizations)

I)

{

I = 10; //Error!

}

(5) It provides a reference for function overloading. For example:

classes

a

{

......

empty

f(int

I)

{......}

//A function

empty

f(int

I)

constant

{......}

//Overloading of the last function

......

};