There are two types of C constants: primary and secondary. Primary constants include integer, real, character, string, and escape sequence constants. Integer constants can be decimal, octal, or hexadecimal. Real constants represent fractional values in decimal or exponential notation. Character constants are single characters within single quotes. String constants are sequences of characters within double quotes. Escape sequences use backslashes to represent special characters like newlines. Secondary constants include arrays, pointers, structures, unions, and enums.
2. TYPES OF C CONSTANTS
C Constants
Primary Constants Secondary Constants
Integer Constants Array, Pointer ,
Real Constants Structure , Union
Character Constants Enum etc.
String constants
Escape sequence
*CONSTANT is a Quantity that doesn’t change……
3. INTEGER CONSTANTS
- sequence of digits
Three types
Decimal: set of digits,0 through 9
123, -87, 0, +56 <- valid $1000, 15 750, (20,000) <-Invalid
Octal: combination of 0 to 7 with leading zero. i.e. 075,
051 are octal
Hexadecimal: sequence of digits 0-9,A..F/a..f …..
Preceded by 0x or 0X
like 0x2, 0x3A, 0Xe5,etc are hexadecimal numbers.
4. REAL CONSTANTS(FLOATING POINT)
- to represent varying entity like prices. it contain
fractional parts.
in decimal notation 34.32, -0.56, .4555 , 0.00054 etc.
In exponential notation(or scientific) 215.65 may be
written as 2.1565e2 also valid
More 0.65e4 ,12e-2, 3.18E3.
-> Should the following be valid ?
1.5E2.5 (YES / NO ) ?
5. SINGLE CHARACTER CONSTANTS
-a single character enclosed within a pair of single
quote marks I.e ‘y’ , ‘4’, ‘;’ , ‘ ‘, etc.
- character constants have integer values known as
ASCII (American Standard Code for Information
Interchange) values.
i.e. printf(“%d”,’a’); will print no. 97, the ascii value of
the letter a.
While printf(“%c”,97); will print --- a
*error in book statement instead of ’97’ it should be
only 97
6. STRING CONSTANTS
-sequence of characters enclosed in double quotes
like
“hello!” , “hi 18”, “well done”, “a”
Remember that “x” and ‘x’ is different because ‘x’ has
equivalent integer value in ASCII.
String constants are normally used like displaying
menu/messages.
7. BACKSLASH CHARACTER CONSTANTS
- used in output functions…
- ‘n’ stands for new line character
- ‘b’ for back space
- ‘t’ for making horizontal tab
all above represents one character, although they
consist of two chars.
These char combination are known as “escape
sequences”