Chapter 2
Chapter 2
The character set refers to a set of all the valid characters that we can use in the source
program for forming words, expressions, and numbers.
A character set in C Programming Language is set of all valid character which is used to form a
words, numbers and expression’s in source program.
The character set is fundamental raw material of any language and they are used to represent
information like natural language, computer language will also have well defined Character set
that is useful to build the programs.
Trigraph characters
C introduces the concept of “trigraph” sequences to provide a way to enter certain characters that
are not available on some keyboards.
Each trigraph sequences consists of three characters (two questions marks followed by another
character.
For example, if a keyboard does not support square brackets, we can still use them in a program
using the trigraphs??(and??).
C Tokens
In a C program the smallest individual units are known as C tokens. Tokens in C is the most
important element to be used in creating a program in C. tokens in C is the building block or the
basic component for creating a program in C language. Tokens in C language can be divided into
the following categories:
i) Keywords
ii) Identifier
iii) Constants
iv) Strings
v) Special Symbols
vi) Operators
Every C word is classified as either a keyword or an identifier. All keywords have
fixed meaning and these meanings cannot be changed. Keywords serve as basic
building blocks for program statements.
A keyword is a reserved word. You cannot use it as a variable name, constant name,
etc.
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.
o The first character of an identifier should be either an alphabet or an underscore, and then
it can be followed by any of the character, digit, or underscore.
o It should not begin with any numerical digit.
o In identifiers, both uppercase and lowercase letters are distinct. Therefore, we can say
that identifiers are case sensitive.
o Commas or blank spaces cannot be specified within an identifier.
o Keywords cannot be represented as an identifier.
o The length of the identifiers should not be more than 31 characters.
o Identifiers should be written in such a way that it is meaningful, short, and easy to read.
Variables in C
A variable is a name of the memory location. It is used to store data. Its value can be changed,
and it can be reused many times.
It is a way to represent memory location through symbol so that it can be easily identified.
Constant
Constant in C refer to fixed values that do not change during the execution of a program
Numeric constant
Integer constants
Real constants
Character constant
Single character constants
A single character constant contains a single character enclosed within a pair of single
quote marks. Example of single character constants are: ‘5’, ‘x’ etc. character constants have
integers value name as ASCII values
printf(“%d”, ‘a’); would print the number 97, the ASCII value of the letter a.
The statement printf(“%c”,’97’); would output the letter ‘a’.
String constants