How to decide which integer type we should use inside program ?
Question : Here How One Should Decide Which Data Type of Integer we should use in order fulfill our requirement ?
Answer :
- Integer Data Can be Divided can be used up to great extend depending upon application.
- Char can hold values up to 127
- Short int and int can hold values up to 32,767
- Long int can hold values up to 2,147,483,647.
How to Decide ?
- Consider Problem Statement and Then imagine which Variables we are using in the program.
- Decide Scope of the Variable and the probable use of Variable.
- Example : Suppose we are using a Counter that will count 10 numbers then short int is sufficient to store data .
- But if we are writing program that will accept 4-Digit number then we should use integer or long integer depending upon Range.
SIZE(char) <= SIZE(short) <= SIZE(int) <= SIZE(long)