Rules for Constructing int, float, char constants: C


We’ve already learnt how to use int, float and char in our previous video tutorial. Now lets learn the rules to construct integer, float/real, character constants in C programming language.

Related Read:
Rules for Constructing Variable Names: C

Rules for Constructing int, float, char constants: C


[youtube https://www.youtube.com/watch?v=4o-ZJfi559Q]

YouTube Link: https://www.youtube.com/watch?v=4o-ZJfi559Q [Watch the Video In Full Screen.]


Rules for Constructing Integer Constants

1. It must have atleast 1 digit. We can have anything from 0 to 9.
2. If user enters decimal point, it’ll be discarded by the program and only the integer part will be stored in the int variable.
3. We can assign positive or negative digit by appending the digit with + or – symbol. If nothing is specified it’ll be considered as positive.
4. Comma, space etc are not allowed.
5. Allowed range for integer constant is -2147483648 to +2147483647 for Visual Studio and gcc compilers. For Turbo C / C++ compilers allowed range for integer constants is -32768 to +32767.

Invalid Integer Constants
10,000
10 000
999999999999

Rules for Constructing Real Constants

1. It must have atleast 1 digit. Anything from 0 to 9 is allowed. If decimal value is not specified compiler will insert 0s for decimal value.
2. It can be either positive or negative value. If + or – symbol is not specified, it’ll be considered as positive.
3. No comma or space allowed.

Rules for Constructing Character Constants

1. Character constant must have only single alphabetic or Single digit or special symbol and must be enclosed in single quote.

Invalid Integer Constants
“A”
“Microsoft”
‘Apple’
‘123’
“$%^”

Leave a Reply

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