- 1
how do you decide which integer type use?
int,float,long,char
4 Antworten
+ 2
INT
+ 1
if you want to input integers (eg:-4,4) then use int data type.If u want to use a character(eg:$,a) present on your keyboard use char data type. and if u want to use numbers with decimal point use float (eg:5.78) .I don't know about long.
cheers
0
Use of Integer type depends on the need and performance of machine.
short - it is the smallest in size (2 bytes) so its range is small . It is suitable to store small length numbers. Also useful when memory is limited.
int - Mostly used to store integers. Machine dependent size (usually 4 bytes). Useful when storing small length numbers. But range is bigger than short.
long- Use to store large size numbers. Memory size is also more than int and short (8 bytes).
You can also use unsigned type by prefixing these types with unsigned keyword.
unsigned short
unsigned int
unsigned long
By doing this you are neglecting the -ve numbers and now its range is increased and it can store more +ve numbers.
Choosing the right one is all depends on the need . But in most cases int type just makes the things done.
0
Make your choice of the integer type depend on the range of numbers you want to keep in the variable. Chose the integer type that is the best fit for your number range. If you only need positive integers use unsigned. It's that simple.