Pointer arithmetic

If I have an array int a[1];

Why do I have to do *(a + 1) = some_value instead of (a + 1) = some_value
(Why must I include the asterisk?)

I already know I can use a[index] = some_value but I'm trying to understand setting values to arrays using pointer arithmetic.

Thanks for the help.
Last edited on
If you read or follow a C++ book you'll see that * is the dereference operator which allows you to access or use the value stored at the address pointed to by the pointer.

Anyway, if you have an array int a[index];, then to set values of its individual elements, you'll need to declare an integer pointer int *int_Pointer;. Then do this:
1
2
3
4
5
6
7
8
9
10
.
.
.
for(int_Pointer = a; int_Pointer < &a[index]; int_Pointer++)
{
    a = your_value;
}
.
.
.
Last edited on
Ok it makes sense now.
Topic archived. No new replies allowed.