Variables in C Programming
A variable is nothing but a identifier. It is name given to a memory location so that we can manipulate the data on that particular location using the variable name very easily. The data type of the variable specifies what type of data we can store on that memory location and the variable definition specifies where a single data or a set of date can be stored on that particular variable. The value of the variable can be manipulate or change through our programs, so it is called as variable. Syntax for a variable definition is as follows-
On the basis of basic C programming data types , C programming has the following basic variables-
|char||A integer data type is used to store a whole number.|
|int||A integer data type is used to store a whole number.|
|long||It can store value between -2,147,483,648 and 2,147,483,647.|
|short||It can store value between -32,768 and 32,767.|
|float||It can store decimal number up to 6 precision.|
|double||It can store decimal number up to 15 precision.|
Rules for Defining a Variable
As variables in C programming are the actually identifiers, so the rules that have to be followed during naming an identifier are to be followed during naming a variable. These rules are as follows-
- The variable name must be unique.
- A valid variable name may have both uppercase & lowercase letter, digits and underscores. Any other special character or white space within the variable name is not allowed.
- The first letter of a variable name can’t be a digit, it must an alphabet or underscore.
- You can mentioned a variable name of any length. There is no limit of length, however the compiler only consider the first 31st character of it and discriminated other part.
- A keywords can not be use as a variable name.
- As C language is a case sensitive language, so both name and Name are two different variable names in C.
- A variable must be defined before it is used.