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]
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.
Last edited by cpjust; 12-02-2008 at 07:30 AM.
"I am probably the laziest programmer on the planet, a fact with which anyone who has ever seen my code will agree." - esbo, 11/15/2008
"the internet is a scary place to be thats why i dont use it much." - billet, 03/17/2010
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.
It is too clear and so it is hard to see.
A dunce once searched for fire with a lighted lantern.
Had he known what fire was,
He could have cooked his rice much sooner.
I think what you need is dynamic memory.
Vanity of vanities, saith the Preacher, vanity of vanities; all is vanity.
What profit hath a man of all his labour which he taketh under the sun?
All the rivers run into the sea; yet the sea is not full; unto the place from whence the rivers come, thither they return again.
For in much wisdom is much grief: and he that increaseth knowledge increaseth sorrow.
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.
"I am probably the laziest programmer on the planet, a fact with which anyone who has ever seen my code will agree." - esbo, 11/15/2008
"the internet is a scary place to be thats why i dont use it much." - billet, 03/17/2010
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
Compilers can produce warnings - make the compiler programmers happy: Use them!
Please don't PM me for help - and no, I don't do help over instant messengers.
[] 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.
long time no C; //seige
You miss 100% of the people you don't C;
Code:if (language != LANG_C && language != LANG_CPP) drown(language);
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.Originally Posted by P4R4N01D
Look up a C++ Reference and learn How To Ask Questions The Smart WayOriginally Posted by Bjarne Stroustrup (2000-10-14)
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!