Current location - Plastic Surgery and Aesthetics Network - Plastic surgery and medical aesthetics - C language, the difference between variables and constants, give some examples to understand, thank you! ! !
C language, the difference between variables and constants, give some examples to understand, thank you! ! !
Constants are generally defined by macros and modified by const. In addition, 1, 10, 1.25f, 1.36d are also constants. PS: the following f and d indicate that the values are float and double types. For more information about this, please refer to C primer plus.

For example, #define MAX 32767 // such a MAX constant is defined by a macro.

Const int MAX 32767// The integer constant MAX is defined by the const keyword modifier.

const float PAI 3. 14 15926; //The floating-point constant PAI is defined by the const keyword modifier.

char * const ptr = 0x 12345678; //Pointer constants are defined by const keyword modifiers.

In addition to the above, the legal identifiers seen in C language except function names and keywords are all variable identifiers.

Difference: A constant is a quantity, and its value can be set at the time of definition (except for numerical constants), but its value cannot be changed at any time thereafter.

A variable is a quantity whose value can be changed at any time after it is defined.

I hope the above answers are helpful to you. Good luck!