hello! i just have a quick question about array. Is there anyway i can set my array declaration [ ] to infinity? because i don't want to set a huge number in the array declaration like [10000000]
Printable View
hello! i just have a quick question about array. Is there anyway i can set my array declaration [ ] to infinity? because i don't want to set a huge number in the array declaration like [10000000]
If you have an infinity-bit CPU and infinity bytes of RAM, then yes.
Although in that case your program would probably take infinite time to run too. :p
There is a MAX_INT constant that represents the largest size an integer can hold, but no system with an operating system can create an array of that size.
You should choose a preferred size and declare that as a constant. Use the constant to declare your array. Also, just because your array is very large does not alleviate the need to make sure that user input is not even longer.
I think what you need is dynamic memory.
all right guys! thanks for the tips and advice!
You could also use C++ instead of C. Then you wouldn't have to worry about the buffer size, since std::string will grow as needed.
If you had said MAX_LONG or MAX_SIZE_T or some such, then I would have agreed. However, a int array[MAX_INT] is "only" 8GB, so a 64-bit machine with plenty of memory can do that without even breaking into a sweat. (each AMD64 processor can deal with 32GB in an Opteron type setup).
Ok, so I have never actually had in my posession a machine with more than 6GB of RAM, but it's certainly not "no system with an operating system can create an array of that size" scenario. I've been told we have one (or pair of?) server(s) here where I work that has 1TB or RAM (or if it was 256GB that can be extended to 1TB?).
--
Mats
[] doesn't mean infinity. It simply means "i dunno"
Why don't you use a dynamic table with pointers?
Why do u need an array that big? You know very well that computers cannot evaluate infinity so u should only think about it in manual (e.g. paper-based) operations. Pointers seem like a better idea, but u will never get unlimited space in which to store an array of infinite size, it just cannot happen. If it could, the exact value of pi would be common knowledge.
More likely davewang merely needs a large array of a size that cannot be determined at compile time. One solution to this is to define an array as large as you would ever need, and since davewang does not know how much is needed, defining an array of infinite size sounded right. In reality, what davewang probably wants is an array whose size can change dynamically to meet the runtime requirements, hence hauzer's suggestion is probably the most appropriate.Quote:
Originally Posted by P4R4N01D
yo got my mind laserlight! that's something that i'm struggling on! now, things is clear! probably have to consider back to set an appropriate value for the array! thanks guys anyway!