When your question is answered use !solved to mark the question as resolved.
Remember to ask specific questions, provide necessary details, and reduce your question to its simplest form. For tips on how to ask a good question run !howto ask.
40 messages · Page 1 of 1 (latest)
When your question is answered use !solved to mark the question as resolved.
Remember to ask specific questions, provide necessary details, and reduce your question to its simplest form. For tips on how to ask a good question run !howto ask.
what do you use for input
ok. In C++ the size of an array can't be dynamic (unless you create the array with new)
what you'd really want to use here is std::vector<int>
actually it can be...
print out your variable n before the array is created
no, those are called VLAs and aren't allowed in C++
more than likely it'll end up being 0 as this is near the start of the program
your array will not be on the heap, it will be on the stack frame, limited to 2MB
do the math
and switch to a dnamically allocated data structure instead
did you print n like I said
before the array
if you reboot your machine it can change
so, an array with 6.4 million elements
stored in the stack frame whose size is 2MB
there's not enough space on the stack frame for this
get it?
each element takes sizeof(string) bytes
not enough space in the stack frame, yes
use a hardcoded counter, like 100 or something
because I know where in memory local variables live, that's why
unlike in python where every f*cking thing is in the heap
well, set n to be a const too
that way the compiler can see that this is a fixed length array
and produce more optimised code
well is n based on the user input? it seems that it is in the code you have right now
no. the size of c arrays is fixed
and the only way to change it is to create a new array
no, once the array is created you can't extend it
if this is an assignment that limits you to c arrays, then use new[], if you can use other stuff then use std::vector
std::vector is the equivalent of a python list
std::vector is the most used c++ collection and is a dynamic array
thats exactly what it is yes
the syntax about what
This question is being automatically marked as stale.
If your question has been answered, run !solved.
If your question is not answered feel free to bump the post or re-ask.
Take a look at !howto ask for tips on improving your question.