473,320 Members | 1,722 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Doubts on Array Size

Good Day To all,

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.....

In VC++,where char range is -128 to +127,am i allowed to declare array
size out of this range...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)........

Expecting your views....

Thanks in advance

Oct 24 '06 #1
2 2377

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.

Oct 24 '06 #2

Harry wrote:
Good Day To all,

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.....
I think you are confusing two concepts.

1) The range of valid index values for the array. As C indexes from 0,
a 45-element array has index values from 0 to 44.

2) The range of valid values which can be stored in an element of the
array. In this case, elements of the array are "plain" char items (by
"plain" I mean they are not qualified as either signed or unsigned) and
your compiler takes them as signed char items. So the range of valid
values which can be stored in any element is -128 to +127.

Does that clarify your question?

Oct 24 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: Herrcho | last post by:
in K&R Chapter 6.3 it mentions two methods to calculate NKEYS. and points out the first one which is to terminate the list of initializers with a null pointer, then loop along keytab until the...
14
by: suman kar | last post by:
Hi all, Please clarify the following piece of code: <CODE> /* delete node containing i from list pointed to by lp */ struct list *lp, *prevlp; for(lp = list; lp != NULL; lp = lp->next) {...
6
by: ritesh | last post by:
Hi, I have been reading some text on C and C++ (i.e advanced books). One of the books mentioned that C++ requires a runtime support whereas C does not - what the author was trying to say was...
17
by: ranjeet.gupta | last post by:
Dear All Below are the few doubts which I got while studying about C 1. Is there any method in C by which we can process the entire string in one unit, 2. Does there exist any way to...
8
by: lovecreatesbeauty | last post by:
Hello experts, I have seen following the code snippet given by Marc Boyer (with slight changes by me for a better format), and have doubts on it. I am so grateful if you can give me your kindly...
12
by: divya | last post by:
1. If The size of the array is unknown during programming time then how is such array declared?? Suppose there is an Array named arrClashname(size unknown at start), Now when the clash occurs...
24
by: temper3243 | last post by:
Hi, Many people have used this code in my project. It works because b is using the extra memory for other 4 variables.I access obj max. well here are a few questions 1) Where does it fail. I...
4
by: arulkumara | last post by:
/wd/arul>exp Export: Release 9.2.0.5.0 - Production on Thu Aug 9 01:52:39 2007 Copyright (c) 1982, 2002, Oracle Corporation. All rights reserved. Username: finuser Password:
28
Nepomuk
by: Nepomuk | last post by:
Hi! I've read, that in C++ there's no predefined method, to calculate the size of an array. However, it's supposed to work withsizeof(array)/sizeof(array)Now, this does work in some situations, but...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.