i hav e a few questions about pointers:
1)
int array[100];
int *ch;
ch=array;
is it true?if it is true why we use pointer becouse it can be likle that int array[100];
....
....
array[i];
is this for dynamic memory
i hav e a few questions about pointers:
1)
int array[100];
int *ch;
ch=array;
is it true?if it is true why we use pointer becouse it can be likle that int array[100];
....
....
array[i];
is this for dynamic memory
There is no need for a pointer in your simple example. Dynamic arrays in the way you mentioned is not possible (perhaps on some compilers), so you need to use pointers and dynamic allocation instead:
int* MyArray;
MyArray=(int*)malloc(i); //Syntax?
...
free(MyArray);
MagosX.com
Give a man a fish and you feed him for a day.
Teach a man to fish and you feed him for a lifetime.
>int array[100];
>int *ch;
>ch=array;
This is valid, but doesn't get you any more than 100 ints
ch[i] accesses the same memory as array[i]
Just a slightly different way of going about it
If you want to choose the size at run time, then
int size = 100;
int *ch = malloc( size * sizeof(int) );
You may want to do a search of dynamic arrays on c board, because just last week I recieved help on this same topic from Prelude. If you cant find it let me know and I can find it and link it for you.