Please enable JavaScript.
Coggle requires JavaScript to display documents.
Symbolic Constants and Macros, Converting Arithmetic Types - Coggle Diagram
Symbolic Constants and Macros
Symbolic constants and macros are essential tools in programming that improve code readability, maintainability, and efficiency.
Symbolic constants
A symbolic constant is a name that represents a constant value in a program.
Defining
Using #define (Preprocessor Directive)
Using const (Keyword)
Macros
A macro is a fragment of code that is replaced by a specific value or code during the preprocessing phase, before compilation.
Defining
Macros are defined using the #define directive.
Advantages
good readability:
easy to modify
Macros for character classification
isalpha(c) Checks if c is an alphabetic character.
isdigit(c) Checks if c is a numeric digit.
isspace(c) Checks if c is a whitespace character.
tolower(c) Converts an uppercase character to lowercase.
toupper(c) Converts a lowercase character to uppercase.
Converting Arithmetic Types
You can generally assume that the “smaller” type will be converted to the “larger” type. :!:
Integer Promotion
bool, char, signed char, unsigned char, and short are converted to int.
bool < char < short < int < long < long long < float < double < long double
Explicit type conversions
(type) expression
static_cast<type>