CHARACTER SET
Every programming language has its own set of characters to form
the lexical elements. The characters used in C are grouped into the following
three categories.
1 Alphabet Upper Case A-Z and Lower Case a-z
2 Digits 0 to 9
3 Special Characters
, comma + plus sign
. dot - minu sign
: colon * asterisk
; semicolon / slash
‘ opostrophe % percentage
“ quotation mark & ampersand
? question mark ^ caret
! exclamation mark ~ tilde
_ underscore < less than
# hash > greater than
= equal sign \ back slash
| pipeline character (
left parenthesis
) right parenthesis [
left bracket ] right bracket
{ left brace } right brace
C
TOKENS
The basic and the smallest units of a C program are called C
Tokens.
There are six types of tokens in C.
1 Keywords
2 Identifiers
3 Constants
4 String
5 Operators
6 Special Symbols
KEYWORDS
Every word in a C program is either a keyword or an identifier.
All keywords (reserve words) are basically the sequence of characters that have
one or more fixed meaning. All C keywords must be written in lowercase letters.
Because, in C both uppercase and lowercase letters are significant.
Example for
Keywords :
int |
char |
break |
else |
if |
continue |
do |
float |
goto |
long |
return |
for |
short |
static |
auto |
union |
struct |
switch |
IDENTIFIERS
Identifiers
are names given to the program elements such as variables, arrays and
functions.
Basically,
identifiers are the sequences of alphabets and digits.
Rules
for forming identifier name
· The first character must be an
alphabet (upper case or lowercase) or an underscore ( _ )
·
All
succeeding characters must be either letters or digits
· Uppercase and lower case
identifiers are different in C
· No special character or
punctuation symbols are allowed except the underscore ( _ )
·
No two
successive underscores are allowed
·
Keywords
should not be used as identifiers.
CONSTANTS
:
A Constant is an entity whose value does not change during program
execution. The following are types of constants :
1
Integer Constant :
An integer constant is a whole number. It is a sequence of digits
without a decimal point. It may prefixed with plus or minus sign.
Example : 246, 0, -3579, +25, -32028, 9999 etc.,
2
Floating Constant :
A floating constant is a number
with a decimal point. It is defined as sequence of digits preceded and followed
by the decimal point. They may have prefixed plus or minus sign.
Example : -246.01, +12.25, 0.0, 0.0005, 82.0, 9999.999, -0.00123
etc.,
3 Character Constant :
A character constant is a single character enclosed within pair of
apostrophes.
Example : ‘a’, ‘?’, ‘#’, ‘ ‘(blank character) etc.,
4 String Constant :
A string constant is a sequence of characters enclosed within a
pair of double quotes.
Example : “Hi”, “Welcome”, “2007”, “x+2”etc.,
VARIABLES
A variable is an entity used by a program to store values in the program.
It is a symbolic name used for
actual memory location. Therefore variable are also called as identifiers.
Example : sum, area, num, length, age, city etc.,
Rules
for forming variable names
· The first character of a variable
name must be an alphabet or an underscore
· All succeeding characters
consists of letters and digits
·
Both
uppercase and lowercase variables are significant in C
· Keywords should be used as variables
· Special characters are not allowed
· There is not limit on the number
of characters in a variable name
·
Always
choose an appropriate variable name that makes proper sense to the user
DECLARATION
OF VARIABLES
All the variables must be declared before they are used in the
program. A variable declaring consists of a data type name followed by a list
of one or more variables of that type, separated by commas.
Syntax :
Datatype Variable_name,…..,….;
Example :
int num;
char name[10]; float rate;
ASSIGNING
VALUES TO VARIABLES
We know that the variables represent some memory location, where
the data is stored. Each variable is associated with one or more values. The
process of giving values to variables is called assignment of values. The
assignment operator ‘=’ is used to assign a value to a variable.
Syntax :
variable_name = value;
Example :
int num=5; float pi=3.142; x = 10;
sum = a + b;
name = “Saraswati”
DATA
TYPES
Data type indicate the type of
data that a variable can hold. The data may be numeric or non- numeric in
nature. There are four fundamental C data types
Types |
Keyword |
Size(in bytes) |
Integers |
int |
2 bytes |
Real
(Floating point) |
float |
4 bytes |
Double Precision |
double |
8 bytes |
Character |
char |
1 byte |
int :
This is
keyword used to indicate an integer number. Any integer number is a sequence
ofdigits without a decimal point. A 8 bit computer the maximum integer that can
be input is either - 128 or +127. Similarly, a 16 bit computer handles the
integers from -32,768 to +32,767.
Example :
-248, 14042, 27246, +1996,0, 32760
float :
This is a
keyword used to indicate a floating-point number. The floating-point numbers
are
same as real
numbers. They are called floating point. These numbers may be expressed in
scientific notation.
Example : -263.238, 2.63238E+02, 0.0263238E+04, 26323.802
char :
This is a
keyword used to indicate the character type data.
The data may
be a character
Constant or a string constant. A character constant can be defined
as any single character enclosed within a pair of apostrophes.
Example :
‘a’, ‘p’,
‘$’, ‘2’, ‘?’, ‘ ‘(blank) etc.,
double :
This is a keyword used to indicate a double precision floating
point numbers. The precision is associated with the accuracy of data. The float
usually stores a maximum or 6 digits after the decimal point. But double stored
16 significant digits after the decimal point.
Example : 234.0000000000000000, -0.0000001023999001
BACKSLASH
CONSTANTS
A backslash
constant a combination of two character in which the first character is
always the backslash( \ ). And the
second character can be any one of the characters a, b, f, n, r, t, v , ’, “,
\, and 0.The backslash characters also called as escape sequences. These
statements are used in output statements.
Backslash Constant |
Meaning |
\a |
System Alarm (bell or beep) |
\b |
Backspace |
\f |
Form feed |
\n |
New line |
\r |
Carriage return |
\t |
Horizontal tab |
\v |
Vertical tab |
\” |
Double quote |
\’ |
Apostrophe |
\0 |
Null character |
\\ |
Back slash character (\) |
SYMBOLIC
CONSTANTS
A symbolic constant is a name that substitutes a numeric constant,
a character constant or a string constant. For example, assume that we are
computing the area of a circle using the formula.
area = 3.142 * radius * radius
In this formula, the numeric constant 3.142 can be replaced by
symbolic constant name PI. Thus, the formula takes a new form as
area = PI * radius * radius
Here, we substituted PI for a numeric constant. During
compile-time, each occurrence of PI is replaced by its value defined. Symbolic
constants are defined using preprocessor statement #define.
Example :
# define PI 3.142
# define NAME “PRABHU”
# define FOUND 1
Symbolic constants must be defined at the beginning of a program.
That is, before the main( ) function of a C Program.
No comments:
Post a Comment