What is the difference between
int *arp = NULL;
int c;
++arp[c];
And
int *arp = NULL;
int c;
arp[c]; c++;
Please I need to know the meaning of this increment ++arp[c];
What is the difference between
int *arp = NULL;
int c;
++arp[c];
And
int *arp = NULL;
int c;
arp[c]; c++;
Please I need to know the meaning of this increment ++arp[c];
++arp[c];
This dereferences arp[c]
(same as *(arp + c)
) and then uses the pre-increment operator to increase the value in arp[c]
by 1. c
remains unchanged.
arp[c];
c++;
This dereferences arp[c]
but doesn't do anything with it so it's pointless. After that it uses the post-increment operator to increase c
by 1. arp[c]
remains unchanged.
Note: Both snippets have undefined behavior because arp
points at NULL
and c
is unintialized when you read from it.