Constants in C

Constants are identifiers whose associated value cannot be altered during the execution of the program.

#define VARIABLENAME value 

const dataType VARIABLENAME = value;


You can either use #define preprocessor form to define a constant (at the preprocessor part of the code/beginning) or the const prefix to declare constant with a specific type (within the main code).

It is common practice to capitalize the entity of the variable name for constants.

dataType is the type (boolean, float, int, etc.) of the specified variable.

#define AGE 20 

const int NEW_AGE = 21;

See Also

GNU C Manual - Constants

Add to Slack

< Local Variables   |   Array >

© 2019 SyntaxDB. All Rights Reserved.