Unit 4 - Declaring Constant

Posted on Friday, May 7, 2010 by B[H] | 0 comments
Labels:

Constant are values that do not change during program execution. They can be of type integer, character or floating point. To declare a constant, use the keyword const as in the example:-

Photobucket

a-Integer constant

Integer constant can be further categorized into four types-short integer, integer,unsigned integer and long integer.
Examples of integer constants

• Short integer constant:
-99 -35 0 45 320

• Integer constants:
9999 -1 0 555 32767

• Unsigned integer constants:
1 256 1000 60000

• Long integer constants:
222 0 33333 9999999

A constant can also be identified as being long by tagging a l or a L to the end of the number, For example , the constants 212L and 323l. will be viewed by C++ as long constants.



b-Character and string Constants

A character constant is any character enclosed between two single quotation marks (‘ and ‘ ). When the several characters are enclosed between two double quotation marks (‘ and ‘ ), it is called a string. Examples of character and string constants;

i. Character constants:
‘$’ ‘*’ ‘ ‘ ‘z’ ‘G’

ii. String constants:
“Name:” “Telephone No:” “Postcode:”

iii. Floating Point Constants
A floating point constant is a decimal number that contains the decimal point (.) or the exponent ( e or E ) or both. Here are some examples of floating point constants.
5.0 0.005 2000.0 987.123 5e-3 0.01e-2 0.2345E8 1.23E4

No comments:

Post a Comment