Constants in c programming

This discussion is in continuation with c language programming character sets.

Rules for Constructing Integer Constants :

1. It must not have a decimal point.
2. It can be either positive or negative.
3. If no sign precedes an integer constant it is assumed to be positive.
4. No commas or blanks are allowed within an integer constant.
5. The allowable range for integer constants is -32768 to 32767.
6. An integer constant must have at least one digit.

Truly speaking the range of an Integer constant depends upon the compiler. For a 16-bit compiler like Turbo C or Turbo C++ the range is –32768 to 32767. For a 32-bit compiler the range would be even greater. Till that time it would be assumed that we are working with a 16-bit compiler.

Ex.: 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. Following rules must be observed while constructing real constants expressed in fractional 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.

Ex.: +325.34
426.0
-32.76
-48.5792

The exponential form of representation of real constants is usually used if the value of the constant is either too small or too large. It however doesn’t restrict us in any way from using exponential form of representation for other real constants.

In exponential form of representation, the real constant is represented in two parts. The part appearing before ‘e’ is called mantissa, whereas the part following ‘e’ is called exponent. Following rules must be observed while constructing real constants expressed in exponential form:

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.
5 . Default sign is positive.
6 . Range of real constants expressed in exponential form is -3.4e38 to 3.4e38.

Ex.: +3.2e-5
4.1e8
-0.2e+3
-3.2e-5

Rules for Constructing Character Constants :

1 . A character constant is 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. For example, ’A’ is a valid character constant whereas ‘A’ is not.

2 . The maximum length of a character constant can be 1 character.

Ex.: 'A'
'I'
'5'
'='
If you are looking for advanced java programming basics try here.



2 comments:

  1. Hi,

    I am Richa from SiliconIndia. I am also an avid blogger for a while now and participating actively in Indian blogosphere. I read your blog posting and found them very interesting and informative. We would love to see a copy of your blogs posted here, whenever you are posting it on blogger.com. Here are some of the benefits of posting your blogs here:

    We have a strong community of 1 Million professionals
    Best blogs of 2008 to be published in a book "SiliconIndia bLoG PrinT"
    Best blog to be printed in SliconIndia & SmartTechie magazines each month
    Chance to be featured on homepage everyday
    There are 10,000 active bloggers who participate in active blogging

    We appreciate your community initiative here and in helping build a more powerful India! Also, if you have any ideas or want to volunteer to help for SiliconIndia, we would be more than excited to get your help. Pls mail me back at richa@siliconindia.com with your suggestions and feedback.

    Richa
    Blog Editor – SiliconIndia

    ReplyDelete
  2. Hi richa,

    Let me know the url where i have to share the data and from which url home page this community is participating ?

    I browsed through your blog and not able to find out.
    Let me know and any way thank for being here.

    ReplyDelete