B.Bhuvaneswaran, AP (SG)/ CSE
9791519152
bhuvaneswaran@rajalakshmi.edu.in
Programming Logic
Constants
2.
Constants
Constants Rajalakshmi EngineeringCollege 2
Rajalakshmi Engineering College 2
Character Set
The character set is a set of valid characters that a language can
recognize.
A character represents any alphabet, digit or special symbols,
which can be used to form variables, numbers and expressions.
3.
Constants
Constants Rajalakshmi EngineeringCollege 3
Rajalakshmi Engineering College 3
Character Set - Groups
Letters / Alphabets
Digits
Special characters
White spaces
Character
Set
Letters /
Alphabets
Digits
Special
Characters
White
Spaces
4.
Constants
Constants Rajalakshmi EngineeringCollege 4
Rajalakshmi Engineering College 4
Character Set - Groups
Letters / Alphabets
Uppercase A . . . Z
Lowercase a . . . z
Digits All decimal digits 0 . . . 9
Special Characters
Comma , Ampersand &
Period . Caret ^
Semicolon ; Asterisk *
Colon : Minus sign -
Question mark ? Plus sign +
Apostrophe ‘ Opening angle bracket <
Quotation mark “ (or less than sign)
Exclamation mark ! Closing angle bracket >
Vertical bar | (or greater than sign)
Slash / Left parenthesis (
Backslash Right parenthesis )
Tilde ~ Left bracket [
Underscore _ Right bracket ]
Dollar sign $ Left brace {
Percent sign % Right brace }
Number sign #
White Spaces Blank space, Horizontal tab, Carriage return, New line, Form feed
Constants
Constants Rajalakshmi EngineeringCollege 6
Rajalakshmi Engineering College 6
Types of Tokens
Keywords
Identifiers
Constants
Strings
Special symbols
Operators
7.
Constants
Constants Rajalakshmi EngineeringCollege 7
Rajalakshmi Engineering College 7
Examples
float
while
main
price
10
-12.15
“REC”
“cse”
[ ]
{ }
+ -
* /
Tokens
Keywords Identifiers Constants Strings
Special
Symbols
Operators
8.
Constants
Constants Rajalakshmi EngineeringCollege 8
Rajalakshmi Engineering College 8
C Constants
Constants in C refer to fixed values that do not change during the
execution of a program.
9.
Constants
Constants Rajalakshmi EngineeringCollege 9
Rajalakshmi Engineering College 9
Integer Constants
Integer constants are whole numbers (0 through 9) without any
fractional part.
10.
Constants
Constants Rajalakshmi EngineeringCollege 10
Rajalakshmi Engineering College 10
Rules for Integer Constants
An integer constant must have at least one digit and must not
have a decimal point.
An integer constant may be positive or negative. If no sign is
preceded an integer constant, it is assumed to be positive.
Embedded spaces, commas and non-digit characters are not
allowed.
Constants
Constants Rajalakshmi EngineeringCollege 12
Rajalakshmi Engineering College 12
Decimal Integer Constants
Decimal integer constants can consist any combinations of digits
from 0 to 9, preceded by an optional + or – sign.
Constants
Constants Rajalakshmi EngineeringCollege 14
Rajalakshmi Engineering College 14
Octal Integer Constants
Octal integer constants can consist of any combinations of digits
from 0 to 7.
However, the first digit must be zero (0), in order to identify the
constant as an octal number.
For instance, decimal integer 8 will be written as 010 as octal
integer.
Constants
Constants Rajalakshmi EngineeringCollege 16
Rajalakshmi Engineering College 16
Hexadecimal Integer Constants
Hexadecimal integer constants can consist of any combination of
digits from 0 to 9 and letters from A to F (either uppercase or
lowercase represents 10 to 15).
A hexadecimal integer constant must begin with either 0x or 0X.
For instance, decimal integer 12 will be written as 0XC or 0xc as
hexadecimal integer.
Constants
Constants Rajalakshmi EngineeringCollege 18
Rajalakshmi Engineering College 18
Real Constants
Real constants are also called as floating point constants. Real
constants are numbers having fractional parts.
Constants
Constants Rajalakshmi EngineeringCollege 20
Rajalakshmi Engineering College 20
Fractional Form
The fractional form consists of a series of digits representing the
whole part followed by a decimal point and series of digits
representing the floating part.
The whole part or fractional part can be omitted, but not both.
The decimal point cannot be omitted.
21.
Constants
Constants Rajalakshmi EngineeringCollege 21
Rajalakshmi Engineering College 21
Rules for Fractional Form
A real constant must have at least one digit and it must have a
decimal point.
A real constant could be either positive or negative (default sign is
positive).
Embedded spaces, commas and non-digit characters are not
allowed.
Constants
Constants Rajalakshmi EngineeringCollege 23
Rajalakshmi Engineering College 23
Exponential Form
The exponential (or scientific) form of representation of real
constants is usually used if the value of the constant is either too
small or too large.
In exponential form of representation, the real constant is
represented in two parts namely, mantissa and exponent.
Syntax:
mantissa e exponent
or
mantissa E exponent
24.
Constants
Constants Rajalakshmi EngineeringCollege 24
Rajalakshmi Engineering College 24
Rules for Exponential Form
The mantissa and the exponent should be separated by a letter e
(either uppercase or lowercase).
The mantissa and exponent part may have a positive or negative
sign (default sign is positive).
The mantissa and exponent part must have at least one digit.
Embedded spaces, commas are not allowed.
Constants
Constants Rajalakshmi EngineeringCollege 26
Rajalakshmi Engineering College 26
Single Character Constants
A single character constant or a character constant consist of a
single character encloses within apostrophes i.e., single quotes (‘).
27.
Constants
Constants Rajalakshmi EngineeringCollege 27
Rajalakshmi Engineering College 27
Rules for Single Character Constants
A character constant is a single alphabet, a single digit, a single
special symbol or a blank space.
The maximum length of a character constant can be one character.
Constants
Constants Rajalakshmi EngineeringCollege 29
Rajalakshmi Engineering College 29
String Constants
A string constant is a sequence of characters encloses within
double quotation marks ("). Technically, a string is an array of
characters.
The compiler automatically places the null character (0) at the
end of each such string, so the program can conveniently find the
end.
30.
Constants
Constants Rajalakshmi EngineeringCollege 30
Rajalakshmi Engineering College 30
Rules for String Constants
The string constant may be letters, numbers, special characters
and blank spaces.
Every string constant ends up with a null character, which is
automatically assigned.
Constants
Constants Rajalakshmi EngineeringCollege 32
Rajalakshmi Engineering College 32
Points to Remember
A character constant 'B' is not the same as the string constant that
contains the single character "B". The former is the single
character and the later a character string consisting of character B
and 0 (null).
A character constant as an equivalent integer value, whereas
single character string constant does not have an equivalent
integer value. It occupies two bytes, one for the ASCII code of B
and another for the null character with a value 0, which is used to
terminate strings.
33.
Constants
Constants Rajalakshmi EngineeringCollege 33
Rajalakshmi Engineering College 33
Escape Sequences
Certain constants are non-printable, which means that they are
not displayed on the screen or in the printer, called as escape
sequences (backslash character constants).
C supports some special backslash character constants that are
used in output functions.
34.
Constants
Constants Rajalakshmi EngineeringCollege 34
Rajalakshmi Engineering College 34
Escape Sequences
ASCII value Escape sequence Meaning
000 0 Null
007 a Audible alert (bell)
008 b Backspace
009 t Horizontal tab
010 n New line
011 v Vertical tab
012 f Form feed
013 r Carriage return
034 " Double quote
039 ' Single quote
063 ? Question mark
092 Backslash