0

I am trying to understand line 231 here: https://github.com/erich666/GraphicsGems/blob/master/gems/Roots3And4.c

Where it says num += SolveQuadric(coeffs, s + num); with num being an int and s looking to be an array of doubles.

The K&R assumption is because of the function declaration where after parenthesis and before the body curly bracket the type and size of the arrays are defined.

So if this really is an array and an int added, what is the outcome? The int added to every entry in the array? extending the array? or something completely different?

I am trying to port the code and I am not sure how to read this part.

  • `s + num` is equivalent to `&s[num]`. This isn't specific to K&R C, it's still true. – Barmar Nov 14 '22 at 08:41
  • The term you are looking for is "pointer arithmetics" – Gerhardh Nov 14 '22 at 08:41
  • 1
    If you are asking what pointer arithmetic is, then I'd suggest looking it up in a beginner-level C book... You should not have been assigned to the task of porting code if you are still a beginner. – Lundin Nov 14 '22 at 08:47
  • While you are reading about the topic, you might take a look at this question: [why is a\[5\] == 5\[a\]?](https://stackoverflow.com/questions/381542/with-arrays-why-is-it-the-case-that-a5-5a) – Gerhardh Nov 14 '22 at 08:53
  • @Gerhardh Except that's just some "fun joke code". This one might be a bit more informative: [Do pointers support "array style indexing"?](https://stackoverflow.com/questions/55747822/do-pointers-support-array-style-indexing) – Lundin Nov 14 '22 at 08:54

1 Answers1

0
num += SolveQuadric(coeffs, s + num);

where s double array and num is an integer.

s + num gives the reference of the n-th element of the array.

0___________
  • 60,014
  • 4
  • 34
  • 74