Rules for constructing Constants in C

The above video is an extract from the online course – “C Programming: The ultimate guide for beginners” which we are currently working on. Consider subscribing to Youtube channel – Aptuts in order to get latest updates on new videos and online C programming course.

There are rules to be followed in order to create Constants in C. Let us discuss the rules to create constants.

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

Actually, the range of the integer Constants in C depends on the compiler. The above mentioned range is for 16-bit compiler. However, for a 32-bit compiler the range would be even greater.

The integer constants
• Whole Numbers
• E.g. 25, 35, -25, -46
• For 16-bit C Compiler, Computer allocates only 2 bytes in memory.
• 16th bit is sign bit. (if 0 then positive value, if 1 then negative value)

Decimal Integer constant:
• 0 to 9
• E.g.: 49, 58, -62 … (40000 cannot come because it is > 32767)

Octal Integer constant:
• 0 to 7
• Add “0” before the value.
• E.g.: 045, 056, 067

Hexadecimal Integer constant:
• 0 to 9 and A to F
• Add 0x before the value
• E.g.: 0x42, 0x56, 0x67

Rules for constructing Real Constants in C

Rules for constructing Real constants (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) If no sign precedes an real constant, it is assumed to be positive.
5) No commas or blanks are allowed within a real constant.

E.g.: +867.9, -26.9876, 654.0

Rules for constructing Real Constants (Exponential Form)
1) The mantissa part and the exponential part should be separated by the letter ‘e’
2) The mantissa may have a positive or negative sign(default sign is positive)
3) The exponent must have at least one digit
4) The exponent must be a positive or negative integer(default sign is positive)

E.g.: +3.2e-4, 4.1e8, -0.2e+4, -3.2e-4

Rules for constructing Character Constants in C
1) A character constant is an alphabet, a single digit or a single special symbol enclosed within single quotation. For example, ‘S’ is a valid character constant whereas “S” is not as it is enclosed within double quotation.
2) The maximum length of a character constant can be 1 character. C Compiler allots 1 byte of memory

E.g.: ’B’, ’l’, ’#’

To learn more about constants in C, visit – Variable, constant and keyword in C

You may also like...

30 Responses

  1. pediatrics says:

    what is bit i.e. 16 bit?

  2. Anonymous says:

    Refer this link for more info.

    http://en.wikipedia.org/wiki/Bit

  3. Anonymous says:

    Your terminology confuses constant values with constant variables. The “constants” that you describe on this page are referred to as “literals” in order to avoid this confusion 🙂

  4. Anonymous says:

    literals whats that

  5. Anonymous says:

    ya its nice

  6. can someone please tell if the value of a character constant can be negative or not??
    please….need to know it urgently..!

    • Kadri Oluwagbemi says:

      There is nothing like a negative character constant; so far i have not heard of such. Don’t know if there is but as for me it doesn’t exist.

  7. Anonymous says:

    “Yes you can have both positive and negative values”

    -God it

  8. The range of real constants in exponential form is -3.4e38 and -3.4e38. These two values same.What is the actual range of Real constants (Exponential Form)……………..

  9. raghava says:

    The Value of a Character constant can be negative.
    but ASCII Values are positive

  10. Tusharsexy32 says:

    Hey please can you explain all te terms more elaborately??????

  11. Anonymous says:

    wt is 16th bit is a sign bit?

  12. Aun Raza says:

    what is rage of integer constant in 32bit compiler

  13. Anonymous says:

    for 16 bit it is 2^16=65536, here it has both positive & negative so range will be -32678 to 0 to 32767. Now u calculate for 32 bit compiler if necessary.

  14. PLS which value is mantissa and which is exponential among these? -3.2e-4

  15. Anonymous says:

    plz explain real constant plz need it for an examination

  16. Anonymous says:

    very good, best site to learn c

  17. Bharath says:

    5) The range of real constants in exponential form is -3.4e38 and -3.4e38 is this right or it is +3.4e38.

  18. LearnCOnline says:

    Hello Bharath, Thank you very much for pointing out that mistake. 🙂 Hope you are finding this website useful.
    In addition, We have recently started a new forum.
    http://forum.learnconline.com/

    You can post your queries and get it resolved.

    Thanks,
    LearnCOnline Team

  19. rati rais says:

    if i hav to convert -296.27 to octal,headecimal n binary form den wat would b d ans rply its very urgent to know………….

  20. ian says:

    -25 and -46 is not a whole number but yet it is an integers.

  21. The range of real constants in exponential form is -3.4e38 and +3.4e38….but in the example 4.1e8 is provided , i think this value is greater than +3.4e38…….. is t correct r i guessed wrong plz answer me sir

  22. Anonymous says:

    sriganth ………dear 4.1e8 means 4.1 multiply by 10 to the power nine ….
    ..which is less 3.4e38 ( which means 3.4 multiply by 10 to the power 38…)

  23. Anonymous says:

    In math ,the value of e is 2.31…………but why this in programming language denotes the power 10 ,…………or i m wrong????

  24. Anonymous says:

    The only problem with this writeup is: You don’t actually explain how to define constants in C. What is the code? What keywords are required? Examples would help as well.

  25. oilo no says:

    Rules for constructing Character constant
    1) A character constant is an alphabet, a single digit or a single special symbol enclosed within inverted commas. Both the inverted commas should point to the left. For example,

  26. Aarti says:

    In Real constants, How many bytes computer allocates in a memory block …?

Leave a Reply

Your email address will not be published. Required fields are marked *