+ 1
Pointers behaving like arrays
Can a pointer store more than one int at a time like an array? I really want to know. Okay now that I know in c++ that a pointer can store different numbers, how can a let a pointer store different numbers and change it when I want to like an array.
1 Odpowiedź
+ 5
Yes, you just need to allocate enough space, for example :
C :
int * p = malloc(3 * sizeof(int));
C++ :
int * p = new int[3];