Rules for constructing constants | C Language Tutorial for Beginners | C Tutorials for Beginners

preview_player
Показать описание
#clanguagebasics #ctutorialforbeginners #ctutorial #clanguagecourse
Rules for Constructing Integer Constants
1. An integer constant must have at least digit.
2. It must not have a decimal point.
3. It could be either positive or negative.
4. If no sign precedes an integer constant it is assumed to be positive.
5. No commas or blanks are allowed within an integer constant.
6. The allowable range for integer constants is -32768 to +32767.
Example
426, +782, -8000, -7605

Rules for constructing Real Constants
Real constants are often called Floating Point constants. The Real constants could be written in two forms, Fractional form, and Exponential form.
1. A real constant must have at least one digit.
2. It must have a decimal point.
3. It could be either positive or negative.
4. Default sign is positive.
5. No commas or blanks are allowed within a real constant.
Example
+325.34, 426.0, -32.76
In exponential form of representation, the real constant is represented in two parts. The part appearing before ‘e’ called mantissa, whereas the part following ‘e’ is called exponent.
1. The mantissa part and the exponential part should be separated by a letter ‘e’.
2. The mantissa part may have a positive or negative sign.
3. Default sign of mantissa part is positive.
4. The exponent must have at least one digit which must be a positive or negative integer. Default sign is positive.
5. Range of real constants expressed in exponential form is -3.4e38 to 3.4e38
Example
+3.2e5, 4.1e8, -0.2e+3

Rules for constructing Character constants
A character constant is either a single alphabet, a single digit or a single special symbol enclosed within single inverted commas. Both the inverted commas should point to the left.
Example
‘A’ is a valid character constant.

The maximum length of a character constant can be 1 character.
Example
‘A’, ‘l’, ‘5’, ‘=’

Types of C variables
Variable names are names given to locations in the memory of computer system where different constants are stored. These locations can contain integer, real or character constants.
The types of variables that it can support depends on the types of constants that it can handle. This is because a constant stored in a location with a particular type of variable name can hold only that type of constant.
Example
1. a constant stored in memory location with an integer variable name must be an integer constant.
2. One stored in location with a real variable name must be a real constant.
3. The one stored in location with a character variable name must be a character constant.

Rules for constructing Variable Names
1. A variable name is any combination of 1 to 8 alphabets, digits, or underscores. Some compilers permit variable names whose length could upto 40 characters. Still, it would be safer to stick to the rule of 8 characters.
2. The first character in variable name must be an alphabet.
3. No commas or blanks are allowed within a variable name.
4. No special symbol other than an underscore can be used in a variable name.
Example: si_int, m_hra, pop_e_89
Рекомендации по теме
join shbcf.ru