Range of data types in c


Following table illustrate the range or maximum or minimum value of data types in TURBO C++ and Borland c++ compilers.


Note: In the above table range of float, double and long double has written only for positive numbers. But this range is also true for negative numbers i.e. for range of float is -3.4*10^38 to -3.4*10^ (-38) and so on.
 
Interview Question: Why range of signed char is -128 to 127 not -127 to 128?
  
Introduction
List of data types
Primitive data types in c
Modifiers of data types in c
List of modifiers in c
Default modifiers of data types in c
Default data of modifiers in c
Rules of using modifiers in c
Possibles modifiers of given data types in c
Size modifier in c
Size of data types in c
Sign modifier in c
Range of data types in c
Easy way to remember limit of data types in c
Const modifiers in c
Pointers modifier in c
Function modifier in c
Interrupt modifier in c
Volatile modifier in c
Fundamental data types in c
Memory representation of char in c
Memory representation of signed char in c
Memory representation of int in c
Memory representation of signed int in c
Memory representation of double in c

14 comments:

ranjith said...

Why range of signed char is -128 to 127 not -127 to 128?...plz comment the answer...

satish said...

char is of size 8 bit so maximum possible value it can occupy is 255 but there is one sign bit too therefor maximum value possible is 127(0(sign bit) + 1111111 (127)) now for +ve no-sign bit is 0 and for -ve no sign bit is 1 and -ve numbers are stored in 1's compliment form i.e 11111111 +1 -> 10000000(128) hence the range is -128 to 127

Unknown said...

In Computers to rep signed numbers the 2's complement signed rep is used
because it has only one zero and the range is given by
-((2^(n-1))) to +((2^(n-1)-1) and here the size of char data type is 1byte i.e., n=8 so its ought to be
-128 to +127
for signed int n=16 in 16-bit compiler or machine so we get -32768 to +32767

Nitin said...

-128 to 127, bcoz 0 also itself is a +ve.
-1 to -128 --> 128
&
0 to 127 --> 128

But if u sey range is "-127 to 128"
-1 to -127 --> 127
&
0 to 128 --> 128
results as unbalanced range

Unknown said...

NO NEED FOR SO MUCH FUSS AND COMPLICATED LOGIC..

LARGEST NUMBER REPRESENTED BY 8 bits IS (2 RAISED POWER 8 - 1)

Now one bit is reserved for sign ..

so.. FOR THE REMAINING SEVEN BITS (2 RAISED POWER 7 - 1) which equals 127

Anonymous said...

Simple Slap For A Good Question :)

Anonymous said...

long int test;
test = 1440 * 60;

printf("%ld", test); // Why do i get 20864 as result? What's wrong?

Unknown said...

hai ranjith,,
character Data type can hold 256 values generally,,,
that half of the values from positive range and rest are negative..

256 values = 128(+ve) + 128 (-ve)

0 to 127 = 128 values
-1 to -128 = 128 values (if you count upto -127 ,then total became 255.Its wrong.Total should be 256.)
Thats why range is -128 to 127..All the best....Thanking you

Unknown said...

1440*60=86400 which is an integer value so the final output will be 86400-65536=20864

Unknown said...

why does data types have specific ranges?? i mean we cannot perform multiplication addition or any other airthmetic operations for large numbers. in that case we have to use either string or array data types.

Unknown said...

why the data types have only specified ranges??

Unknown said...

0-128=129 na??

Unknown said...
This comment has been removed by the author.
JustChillion8 said...

This is the exact and best answer.This is what I was looking for.Thank you satish bhai!!