pointers - updating local vector entries in c -


int *my_vector has 3 values received master process through mpi_rec..now want subtract first value values , store.e.g

my_vector = { 4,8,12} 

after subtracting first element i.e.4 all, need have these vales{0 4 8} , update/store them in my_vector.

using following code

for (i=0;i<=2;i++) {     my_vector[i]=my_vector[i]-my_vector[0]; } 

the above code subtract first element not others , gives {0 8 12} , not {0,4,8}. in advance

while "normal" forward loop using temporary variables might preferred there alternative of looping backwards:

for (i = 2; >= 0; --i) {     my_vector[i] -= my_vector[0]; } 

Comments

Popular posts from this blog

android - InAppBilling registering BroadcastReceiver in AndroidManifest -

python Tkinter Capturing keyboard events save as one single string -

sql server - Why does Linq-to-SQL add unnecessary COUNT()? -