jeudi 2 novembre 2017

I have an array of pointers. How to correctly assign a value to the locations each element of the array points to?

I have this code declaring an array of pointers and assigning value of 5 to the location that the first pointer in the array points to:

int *p[10];
*p[0]=5;

However, this is showing an EXC_BAD_ACCESS error. I tried

int **p = new int *[10];
*p[0]=5;

But this is giving the same error. How do I assign a value to the location pointed by an element of my array of pointers? Thank you.

Aucun commentaire:

Enregistrer un commentaire