Difference Between Variables and Constants17 Mar 2025 | 4 min read What is a variable?A variable is like a container containing the values or data of a particular data type that helps to execute the program. The value of a variable can change depending on the conditions or information given at the program's run time. A variable can be defined in both ways, like the uppercase and lowercase letters, digits and the underscores. A variable can store the value of the different data types like integer, float, character, enum. Rules for defining the variable name in C programming language:
Declaration of VariablesIt is simple to declare the variables in the C program. Initialization of VariablesIt is the simple initialization of variable in C program: ConstantsA constant is a fixed value whose value cannot be changed during program's execution or once the value is defined. It is also known as literal. For example, 5, 20, 'a', 'Radius', 5.2, "Welcome back", etc. A constant can be defined in two ways, like #define pre-processor and by const keyword. The constants can be different data types, such as integer constants, floating constants, character constants, string constants and enumeration constants. Let's understand briefly about them:
Note: "A" and 'A' are different; the first one is a string constant consisting of character A and \0. While the second 'A' represents is a character constant whose integer value is 65.Example 1: Let's create a program to use the #define pre-processor in C constants. Output: ![]() Example 2: Write create a program to display the use of const keyword in C. Output: ![]() Difference between Variables and Constant in C Program
Next TopicRound Robin Program in C with Output |
We request you to subscribe our newsletter for upcoming updates.