II-14 Programming Concepts
4. Explain different types of constants in C.
Ans: Constants in C are as follows:
1. Numerical Constants
(a) Integer constants: These are a sequence of numbers from 0 to 9 without decimal points or
fractional part or any other symbols. It requires minimum 2 bytes and maximum 4 bytes of
memory. Integer constant could be either positive or negative or may be zero.
Example: -10, 20, +30, -15.
Besides, representing the integers/real constants in decimal number system, they also can be
represented in octal or hexadecimal number system based on the requirement.
(b) Real Constants: Real constants are floating-point constants.
Example: 2.5, 5.521, 3.14.
2. Character Constant
(a) Single character constants: A character constant is a single character (length = 1). It can also
be represented with single digit or a single special symbol or white space enclosed within a
pair of single quote marks.
Example: 'a', '8', '-'.
(b) String constants: String constants are a sequence of characters enclosed within double quota-
tion marks.
Example: "Hello", "India", "444", "a".
5. How the octal and hexadecimal numbers represented in C?
Ans: Numbers or constants can be represented in octal or hexadecimal based on the requirement/
applications.
Octal has base 8 and hexadecimal has base 16. The octal numbers are 0, 1, 2, 3, 4, 5, 6, 7 and hexa-
decimal numbers are 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, A, B, C, D, E, F.
The representation of octal numbers in C would be done with leading digit 0 and for hex representa-
tion with leading 0X.
Following are a few examples of octal and hexadecimal numbers.
027, 037, 072 – Octal numbers
0X9, 0Xab, 0X4 – Hexadecimal
6. What are the C keywords? Elaborate them.
Ans: The C keywords are reserved words by the compiler having fixed meaning. They cannot be
used as a variable name. The 32 C keywords provided in ANSI C are listed in the following table.
auto double int struct
break else long switch
case enum register typedef
char extern return union
const float unsigned short
continue for signed void
M02_ITL-ESL4791_02_SE_C02.indd 14 12/22/2012 4:59:41 PM