Take the 2-minute tour ×

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?

share|improve this question

marked as duplicate by kennytm, wallyk, dirkgently, Tyler McHenry, Brian Sep 3 '10 at 16:24


as in "maximum size across all platforms and implementations?" –  louisgab Sep 3 '10 at 16:15
I mean that how would one get the largest value that he can assign to a variable so overflow cant occur. –  Fahad Uddin Sep 3 '10 at 16:16

2 Answers 2

up vote 3 down vote accepted

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.

share|improve this answer

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... */
share|improve this answer
