Posts

Showing posts with the label constants

Constants in C Programming Language

Constants in C : A constant stores a value that cannot be changed from its initial assignment. By using constants with meaningful names, code is easier to read and understand. To distinguish constants from variables, a common practice is to use uppercase identifiers. One way to define a constant is by using the const keyword in a variable declaration: #include <stdio.h> int main() {     const double PI = 3.14;     printf("%f", PI);     return 0; } The value of PI cannot be changed during program execution. For example, another assignment statement, such as PI = 3.141 will generate an error. Another way to define a constant is with the #define preprocessor directive. The #define directive uses macros for defining constant values. For example: #include <stdio.h> #define PI 3.14 int main() {     printf("%f", PI);     return 0; } Before compilation, the preprocessor replaces every macro identifier i...