+ 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.

16th Jun 2018, 5:47 PM
Shaun Nunoo
Shaun Nunoo - avatar
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];
16th Jun 2018, 6:03 PM
Baptiste E. Prunier
Baptiste E. Prunier - avatar