tags:

views:

46

answers:

2

Possible Duplicate:
How would you set a variable to the largest number possible in C?

Can we find the maximum size of a data type in C langauge?

+2  A: 

There is no maximum size. A data type has a size, and it remains constant in that implementation. You can get it by sizeof(datatype).

If you ask for the maximal number representable by a data type, then for unsigned types you can just do (unsigned type)-1. This is useful if you just use an unsigned typedef (size_t etc) and don't know the exact underlying type name. For signed types, this won't work. There are macros for this though (including the unsigned variants)

INT_MAX /* maximal int value */
LONG_MAX /* maximal long value */
UINT_MAX /* maximal unsigned int value */
/* etc... */
Johannes Schaub - litb
+3  A: 

If you want to know the maximum and minimum values you can store in a variable of a given data type, you can check with these different constants:

LONG_MIN, LONG_MAX, see here, for the rest.

Live