P
perez.angela7
Hi all,
I'm a student who just started programming in C. I have the following
question: if I want to shift the elements of an array and insert a new
value as the last element, I use this syntax (for an array a of
elements size):
for (i=0; i < size-1; i++)
a=a[i+1]
a[size-1]=newValue;
But it turns out that this works too:
int *p_i;
p_i=&a[1];
a[size-1]=newValue;
Now, the pointer method seems more efficient to me. But because I'm
not an expert on C (just started last week), I would like to know your
thoughts on this - which is the preferred method? am i right in
thinking the pointer method is more efficient? Any thought, or
pointers (no pun) very welcome.
Thanks for your help
Angela
I'm a student who just started programming in C. I have the following
question: if I want to shift the elements of an array and insert a new
value as the last element, I use this syntax (for an array a of
elements size):
for (i=0; i < size-1; i++)
a=a[i+1]
a[size-1]=newValue;
But it turns out that this works too:
int *p_i;
p_i=&a[1];
a[size-1]=newValue;
Now, the pointer method seems more efficient to me. But because I'm
not an expert on C (just started last week), I would like to know your
thoughts on this - which is the preferred method? am i right in
thinking the pointer method is more efficient? Any thought, or
pointers (no pun) very welcome.
Thanks for your help
Angela