C++ Constant Expressions Vs Macros

C++ Constant Expressions Vs Macros In this post, we will discuss C++ Constant Expressions ( const expr) and how they replace traditional Macros(#define) . Macros in C/C++ Macro is a Preprocessor directive in C/C++ used to define expressions with names. Before compilation, the Preprocessor will search for the name in the entire code and replace it with the expression. Below is an example of how to define a macro identifier with a value #include<stdio.h> //here are defining a macro #define PI 3.14 int main () { int radius = 5 ; /* * In the below code Preprocess replace PI with 3.14 before compilation */ int area_of_circle = PI*radius*radius; printf( "Area is : %d\n" ,area_of_circle); int perimeter = 2 *PI*radius; printf( "Perimeter is : %d\n\n" ,perimeter); return 0 ; } Below is an example of how to define a macro expression #include<stdio.h> //her are defining a macr...