Variables and Identifiers

Back - C Language Notes By Vivek Sir email: vivekdubey22@gmail.com (w) 9826424484

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

  1. Both an identifier and a variable are the names allotted by users to a particular entity in a program. The identifier is only used to identify an entity uniquely in a program at the time of execution whereas, a variable is a name given to a memory location, that is used to hold a value.
  2. Variable is only a kind of identifier, other kinds of identifiers are function names, class names, structure names, etc. So it can be said that all variables are identifiers whereas, vice versa is not true.

Keywords and Identifiers

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.

 

Back - C Language Notes By Vivek Sir email: vivekdubey22@gmail.com (w) 9826424484