In this tutorial, we will learn variables and constants in c programming, and the rules for naming a variable, and the difference between variables and constant. So let us start.
A Variable is a strong area that is used to store the data. The Variable stores the data and during the time of program execution the value of the variable can be changed. The value of the Variable can be changed even after the declaration of value.
Every variable should have a unique name to indicate the storage area properly. Variables are just a symbolic representation of the memory location at which the data is stored.
It is a variable of the function which is declared outside. It can be used in any of the functions. It can be declared anywhere outside the block. The value of the global variable can be changed by any function inside the code.
This variable is declared inside the function. The local variable is used only where the function is declared. It should be declared at the starting of the block.
Constant is a variable whose value can not be changed. As we can see from the name itself that these are the variables that will not change or we can say will remain fixed. Every constant has some range.there are various ranges depending upon the unsigned to signed bits. When we declare any constant its value remains the same throughout the function.
The constant can be of any type like integers, characters, float, octal, hexadecimal, etc. there is a range for every constant.
There are two types of constant. They are user-defined and constant keyboard.
Define is a type of Pre-processor which is used to declare constant declare.
By using the Const keyword we can declare constant.
Constant | Variable |
---|---|
It is a value that can not be altered throughout the program | It is a storage location which is paired with an associated symbolic value consisting of a value |
Value can not be changed | Value can be changed according to the requirement of the user |