Define macros in C header files

https://‮ww‬w.lautturi.com
Define macros in C header files

The macro is used to define some constants. Using macro can make the code clearer and easier to modify.
Example:

/**
* defining a macro in a header file in c language
* PI: Macro name
* 3.1415 :Macro value
* Note: When MAX_ ARRAY_ When LENGTH is called, it will be replaced with 3.1415
*/

#define PI 3.1415

If the same constant is used in several places in your program, it is easier to read and modify using macros

for example

for(i=0;i< 1000;i++){
        
}
if(len < 1000)

while(time > 1000)

If the first and second positions are the maximum array length, and the third position is the value of other variables, they cannot be quickly modified.

Example Using Macro :

#define MAX_ARRAY_LENGTH 1000

for(i=0;i< MAX_ARRAY_LENGTH;i++){
        
}
if(len < MAX_ARRAY_LENGTH)

while(time > 1000)

If you want to modify the maximum length value, you only need to modify the line #define MAX_ARRAY_LENGTH 1000.

Created Time:2017-08-28 15:26:00  Author:lautturi