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.
What are the variables in a c programming language?
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.
What are the types of variables in c?
Global variable
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.
Local variable
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.
What are the rules for naming a variable?
- A variable name can only consist of letters (it can be both uppercase and lowercase letters), digits, and underscore.
- The first letter of a variable should only be either a letter or an underscore.
- There is no such rule on how long a variable name (identifier) can be. However, we may run into problems in some of the compilers if the variable name is longer than 31 characters.
What is constant in c programming?
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.
What are the types of constants in c?
There are two types of constant. They are user-defined and constant keyboard.
User # define
Define is a type of Pre-processor which is used to declare constant declare.
Using const keyboard
By using the Const keyword we can declare constant.
What is the difference between constant and variable?
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 |
Top comments (0)