eh..eXcuse me for this question.. I want to learn..
:rolleyes:
Hello, I need your help with two things:
a) passing variable by reference and by value, what's the differences? what's the uses?
b) it seems like defining an array size must be done with only constans, is it really just this way? if not, how can I define
one (array) with variables (like int A[x][y];)?
thank you very much in advance...
Re: eh..eXcuse me for this question.. I want to learn..
Quote:
Originally posted by mindrebel
b) it seems like defining an array size must be done with only constans, is it really just this way? if not, how can I define
one (array) with variables (like int A[x][y];)?
Use dynamic allocation (new for C++ and malloc() for C). I'm not sure about the syntax for malloc() (always used new :)), but it is something like this:
Code:
//Create a pointer
int* MyPointer;
//Allocate memory
MyPointer=malloc(SizeX*SizeY);
//Check if the allocation was successful
if(MyPointer!=NULL)
{
//*** Do whatever you want ***
MyPointer[y*SizeX+x]=56;
//Deallocate the memory. If you don't do this, you
//will end up with memory leaks. ONLY deallocate if it
//has been allocated, might crash otherwise...
free(MyPointer);
}