Constants in CA constant is a value or variable that can't be changed in the program, for example: 10, 20, 'a', 3.4, "c programming" etc. There are different types of constants in C programming. List of Constants in C
2 ways to define constant in CThere are two ways to define constant in C programming.
1) C const keywordThe const keyword is used to define constant in C programming. Now, the value of PI variable can't be changed. Output: The value of PI is: 3.140000 If you try to change the the value of PI, it will render compile time error. Output: Compile Time Error: Cannot modify a const object 2) C #define preprocessorThe #define preprocessor is also used to define constant. We will learn about #define preprocessor directive later. Visit here for: #define preprocessor directive. Next TopicLiterals in C
|