Hi all can someone please tell me what does this line of code do
xdata.yarray[3] = *(ptr++);
xdata.yarray[2] = *(ptr++);
xdata.yarray[1] = *(ptr++);
xdata.yarray[0] = *(ptr++);
I am trying to figure out someone Else’s code so having problems
would also appreciate if anyone could offer some useful pointers on the best way to decipher someone Else’s code.
Thank you
would the meaning of the code be changed if instead of xdata it was just data
You have plenty of answers as to what this code does. Presumably, coping the contents of some array pointed to by ptr and storing it in reverse order to another array contained within the struct “xdata”.
You asked how you could decipher this on your own, which is an excellent question, best way to learn is to do it yourself. Here’s my advice: take what you know, create your own little program based on that, and view the output.
For example, without seeing all of the code, I know you have an array “yarray” of 4 elements, and you’re storing values from a dereferenced pointer in to it. You could make a little program like below to see how the code reacts:
Now you can see that the code is reversing the order of the contents that ptr is pointing to and storing it in the yarray.