Pointer can become array ?

Jan 29, 2016 at 6:39am
Example if i write int* a;
a[10]=5;can ?
Jan 29, 2016 at 6:53am
It is possible once you enter an address in a, I think. But it is not a good practice and you shouldn't do it. Because the compiler might overwrite the data when you create an another variable. Instead you should try using the pointer with the new operator and then you can do it.
Jan 29, 2016 at 8:34am
You can use array syntax with pointers.

a[10] is the same as *(a + 10). It accesses the 10:th int after the int pointed to by a. If a is pointing to the first element in an array it means it will access the 11:th element in the array.
Last edited on Jan 29, 2016 at 8:35am
Topic archived. No new replies allowed.