Harry wrote:
>
When i am declaring a array for e.g char [45]....it means i am
declaring array of 45 characters each of which has a maximum,minimum
value limit or range...for example in VC++(compiler that i am using,it
has nothing to do with C++) char's range is -128 to +127....this is the
range for each char element.....
My doubt is what is the upper limit for the array size(45 is the size
here) and what decides it.....
The compiler decides it, constrained by the relevant C Standard. For
example, the C99 Standard requires that the compiler must allow an
object to be at least 65535 bytes in size. Your object is an array of
char, so the compiler must let at least [65535] be valid. Many
compilers will allow it to be a lot bigger than this. This minimum size
applies only to "hosted" environments (that is, "normal" situations
where you are compiling a program to run under an operating system, as
opposed to where you are writing the OS or some code for an embedded
controller).
In VC++,where char range is -128 to +127,am i allowed to declare array
size out of this range...
Yes. There is no connection between the values which can be held in
the individual items in an array and the maximum size of the array.
for e.g char[3168].....some say that array
size is int and so it should be within the limits of int,but some say
that some compilers take the range of array size to be same as the
range of the array type...in my case the range for array size is same
as range of char(-128 to +127)........
Ignore everything these "someone"s say about C - they are all wrong. A
variable of type size_t must be able to hold the size of your array,
but the maximum size allowed for an array need not be the same as the
maximum value which can be held in a size_t.