Variables and Identifiers
What is the difference between an identifier and a variable?
The word ‘identifier’ clearly defines itself, an identifier is a name given to an entity, which distinctly identifies an entity in a program at the time of its execution. Variable is also an identifier, its name uniquely identifies itself in a program.
Here, the fundamental difference between an identifier and variable is that an identifier is a “name given to entity” in a program whereas, a variable is a “name given to memory location”, that is used to hold value, which may get modified during program execution.
Key Differences between Identifier and Variable
In 'C' every word can be either a keyword or an identifier.
Keywords have fixed meanings, and the meaning cannot be changed. They act as a building block of a 'C' program. There are total 32 keywords in 'C'.
Keywords are written in lowercase letters.
Following table represents the keywords in 'C',
|
auto |
double |
int |
struct |
|
break |
else |
long |
switch |
|
case |
enum |
register |
typedef |
|
char |
extern |
return |
union |
|
const |
short |
float |
unsigned |
|
continue |
for |
signed |
void |
|
default |
goto |
sizeof |
volatile |
|
do |
if |
static |
while |
An identifier is nothing but a name assigned to an element in a program. Example, name of a variable, function, etc. Identifiers are the user-defined names consisting of 'C' standard character set. As the name says, identifiers are used to identify a particular element in a program. Each identifier must have a unique name. Following rules must be followed for identifiers:
1. The first character must always be an alphabet or an underscore.
2. It should be formed using only letters, numbers, or underscore.
3. A keyword cannot be used as an identifier.
4. It should not contain any whitespace character.
5. The name must be meaningful.