« Previous                                                                  Next Chapter »
Character Set

A character refers to the digit, alphabet or special symbol used to data representation.


S.No

Character Type

Values

1

Alphabets

A-Z, a-z

2

Digits

0-9

3

Special Characters

~ ! @ # $ % ^ & * ( ) _ + { } [ ] - < > , . / ? \ | : ; " '

4

White Spaces

Horizontal tab, Carriage return, New line, form feed


Variables

A variable can be defined as a memory location declared to store any kind of data (which may change many times during program execution). It can also be defined as any quantity/entity which may vary during program execution. To identify a variable (the declared memory location), it can be assigned a name known as variable name.  


Identifier

The name given to a variable is known as an identifier. An identifier can be a combination of alphabets, digits and underscore.

There are certain set of rules which must be observed while naming a variable.


Rules for naming a variable

  • A variable name (identifier) can be any combination of alphabets, digits and underscore.
  • First character should be a letter (alphabet).
  • Length of variable name can range from 1 to 8. (Note: Different compilers may allow different ranges, say up to 31. But it is a good practice to keep the variable name short.)
  • A white space in between is not allowed.                                Ex: A variable name cannot be declared as var name.
  • Underscore can be used to concatenate name combinations.   Ex: var_name , var_123 are valid identifiers.
  • Commas or other special characters (other than underscore _ ) are not allowed in a variable name.
  • C is a case sensitive language which means a variable name declared as flag is not same as FLAG. They both will be treated as different variables.
  • There are certain reserved words in C language, known as keywords. Words similar to a keyword cannot be used as a variable name. Ex: Data types like int, char, float etc. These are actually keywords. So we can’t declare a variable with names int, char or float.


Variable Declaration

A variable must be declared first before we can use it in a program for manipulations. A variable is declared with its storage class, data type and identifier.

Syntax: Storage-class  Data-Type  Variable name; 

There are 4 storage classes namely Automatic, Static, External and Register storage classes. Each of them has its own meaning and usage. Storage class is used to attribute certain features to a variable like its scope (local or global), where to store the variable (in memory or in register), the life time of a variable etc. It is not necessary to specify a storage class while declaring a variable. By default all variable declarations (without any storage class specified) will be assigned to “automatic storage class”. So our variable declaration would be like

Syntax: Data-Type  Variable-name;

Ex:

int a;

int count;

char name; 

Two or more variables of the same data type can be declared in a single line, separating each variable name with a comma and ending the line with a semicolon.

Ex:

int n,count,flag,i,j;

char name,address,nick_nm;

Initial values can be assigned to variables while declaring it.

Ex:

int a,num,count=0,flag=10,mark=100;

char name=Robert,sur_nam=Nero,mid_nam=de; 


Keywords

Keywords are reserved words in C which has a predefined meaning. The compiler already knows the meaning of these words and it will do a particular operation according to the meaning of the keyword.

Ex: 

int is a keyword used to identify an integer quantity. When we declare a variable as int a; the compiler assumes that variable a is used to store an integer quantity. There are 32 keywords in C language. All of them are listed in the table below.                       

auto

do

if

struct

break

else

long

sizeof

char

enum

register

typedef

case

extern

return

unsigned

const

goto

short

union

continue

float

signed

void

default

for

switch

volatile

double

int

static

while


Notes:

  • A keyword name cannot be used as a variable name.
  • Keywords must be written in lower case.


  « Previous                                                                 Next Chapter »