Home Contact About

Constants, Variables and Keywords





C Tokens
In a passage of text, individual words and punctuation marks are called tokens
Similarly, in a C program the smallest individual units are know as C tokens.
C has 6 types of tokens and C tokens are used to write C programs.
  1. Keywords
  2. Identifiers
  3. Constants
  4. Strings
  5. Special Symbols
  6. Operators
Keywords
Every C word is classified as either keyword or Identifier.
All keywords have fixed value, serve's as the basic
building block of C program and must be written in lowercase only.
Some compilers also use additonal keywords and can be identified using
it's mannual.
The list of standard Keywords are:
Identifiers
Identifiers refer to the names of variables, functions and arrays. These are
user-defined names and consists of a sequence of letters and digits, with
a letter as a first character. Both uppercase and lowercase are permitted but
lowercase are usally used.

Rules for Identifiers
  • First character must be an alphabet (for underscore).
  • Must consist of only letters, digits or underscore.
  • Only first 31 characters are significant.
  • Cannot use a keyword.
  • Must not contain white spaces.
Constants
Constants in C refer to fixed values that do not change during
execution of a program.
The diffrent types of C constants are:
Integer Constants
An integer constants refers to a sequence of digits.
It was divided into 3 types:
  • Decimal Integers
    Decimal Integers consist of a set of digits, 0 through 9, preceded
    by an optional - or + sign.
    Examples: 123 , -321 , 0 , 654321 , etc
  • Octal Integer
    An octal integer constants consists of any combination of digits
    from the set 0 through 7, with a leading 0.
    Examples: 037 , 0 , 0551 , etc
  • Hexadecimal integer
    A sequence of digits preceded by 0x or 0X is considered as
    hexadecimal integer. They can also include alphabets A through F
    or a through f. The letter A through F represent the numbers 10 through 15.
    Examples: 0X2 , 0x9F , 0x , etc
Real Constants

Integer numbers are inadequate to represent quantities that vary continuously,
such as distances, heights, tempratures, prices and so on. These quantities
are represented by numbers consisting fractional parts like 17.548. Such
numbers are called real constants(or floating point).
Examples:
0.0083 , -0.75 , 435.36 , 247.0

These numbers are shown in decimal notation (or scientific notation)
For example the value 215.65 may be written as 2.1565e2 in exponential notation.
e2 means multiply by 10^2. The genreal form is:

mantissa e exponent

Single Character Constants

A singlr character constant (or simple character constant) contains a single
character enclosed within a pair of single quote marks.
Examples:
'5' , 'X' , ';'

Note in the above example character constant '5' is not equal to as number 5.
Character constants have a integer values known as ASCII values.
For example:
printf("%d" , 'a');
would print the number 97, the ASCII values of the letter a.

String Constants

A string constant is a sequence of characters enclosed in doubble quotes
THe characters may be letters, numbers, special numbers and blank spaces.
Examples:
"HEllo" , "1987" , "Well Done" , etc

Remember that a character constant is not equivalent to string constant.
Character strings are often used in programs to build meaningful programs.

Backslash Character Constants
C suppourts some special backslash character constants that are used in
oputput functions. For example, the symbol '\n' stands for newline character.
Constants Meaning
\a audible alert (bell)
\b back space
\f form feed
\n new line
\r carriage return
\t horizontal tab
\v vertical tab
\ single quote
\" double quote
\? question mark
\\ backslash
\0 null
Variables

A variable is a data name that may be used to store a data value. Unlike constants
that remain unchanged during execution of a program.

A variable name can be chosen by the programmer in a meaningful way so as reflects
its functions or nature in the program.

As mentioned earlier, Variables names may consists of letters, digits, and the underscore(_)
character.

Some conditions for the variable naming in C are:




Data Types
C is rich in data types. Storage representations and machine instructions to handle
constants differ from machine to machine.
ANSI C suppourts three classes of data types:
  • Primary (or fundamental) data types
  • Derived data types
  • User-defined data types
Primary data types:
  1. Integral type
    • Integer
      1. signed
        • int
        • short int
        • long int
      2. unsigned type
        • unsigned int
        • unsigned short int
        • unsigned long int
    • Character
      1. char
      2. signed char
      3. unsigned char
    • Floating Point type
      1. float
      2. double
      3. long double
    • void


Integer Types

Integers are whole numbers with range of values suppourted by a particular
machine.

IN order to provide control over the range of numbers and storage space, C
has three classes of integers storage, namely short int, int and long int,
in both signed and unsigned forms.

Unlike signed integers, unsigned integers use all the bits for the magnitude
of the number and are always positive.

Floating Data types
FLoating point numbers are all stored on 32bits (on all 16bit snd 32bit computers)
with 6 digits of precision. Floating point numbers are defined in C by the keyword float
When the accuracy provided by the float number is not sufficient double can be used to define the number. The double gives 64bits giving a precision of 14 digits.
To extend the precision long double is used which uses 80bits.
Void types
The void has no values. This is used to specify the type of functions.
THe type of function is said to be void when it does not return any
value to the calling function.
Character Types:

A single character can be defined as a character(char) type data.
CHaracters are usally stored in 8 bits of internal storage. The qualifier signed
or unsigned may be explicitly applied to char. While unsigned chars have values
between 0 and 255, signed chars have values from -128 to 127.