1. ## question about global variabels

I`m planing to make a little game where I whant you to be abel to choose how big a matrix should be I figurd that I probably coul use maloc to creat it as a globel variabel but can I use realloc to make it bigger/smaller? or is the realloc just for the funktion I called it in?

2. malloc:ed and realloc:ed memory can be accessed through your entire program. You can malloc in a function then return a pointer to it and still have access to it outside that function.
Just remember to free it before exiting the program.

3. oh I see I got some vage memory of how you return a pointer to an array... is it?

Code:
```malloc the matrix (forgot how to do it at the moment but I got it wirten down somewhere)
int* i;
*i=matrix[0] [0]
return *i;```

but if it is like this does it mean that I have to send and return it to each funktion I whant to use it in and how do I make it to a matrix in that funktion again???

4. Code:
```int *CreateArray(size_t size)
{
int *i = malloc(sizeof(int) * size);

if (i == NULL)
perror("malloc");

return i;
}```

5. oh and can I make it like this instad?
Code:
```#include "alot of things.h"

int x=12;
int y=12;
int matrix [x] [y]
goto someplace
place
int matrixx [x] [y]
goto back
someplace

int main(){
and then the rest of the program...
}```

6. Originally posted by Hammer
Code:
```int *CreateArray(size_t size)
{
int *i = malloc(sizeof(int) * size);

if (i == NULL)
perror("malloc");

return i;
}```

but how do I use it later on? and where do I tell it how big it should be?

>>where do I tell it how big it should be?
>>but how do I use it later on?
An example:
Code:
```#include <stdio.h>
#include <stdlib.h>

#define SIZE 10

int *CreateArray(size_t size)
{
int *i = malloc(sizeof(int) * size);

if (i == NULL)
perror("malloc");
return i;
}

int main(void)
{
int *myarraypointer;
int i;

myarraypointer = CreateArray(SIZE);

if (myarraypointer != NULL)
{
for (i = 0; i < SIZE; i++)
{
myarraypointer[i] = i;
printf ("myarraypointer[%d] is %d\n", i, myarraypointer[i]);
}
}

free(myarraypointer);
return 0;
}

/* output

myarraypointer[0] is 0
myarraypointer[1] is 1
myarraypointer[2] is 2
myarraypointer[3] is 3
myarraypointer[4] is 4
myarraypointer[5] is 5
myarraypointer[6] is 6
myarraypointer[7] is 7
myarraypointer[8] is 8
myarraypointer[9] is 9

*/```

8. okey hammer I think I get it now I`ll print the link you gave him in school tomorrow and read it carefully (I always have a hard time understanding stuff like that when I read it from a sreen.....hmm sounds like I`m really stupid now....awell)

9. Originally posted by Shogun
okey hammer I think I get it now I`ll print the link you gave him in school tomorrow and read it carefully (I always have a hard time understanding stuff like that when I read it from a sreen.....hmm sounds like I`m really stupid now....awell)
You're not stupid, I have the same trouble. I end up printing loads, and throwing it away the next day

10. hmmm but what if I wanna make an matrix instad?