I am studying the C++ code from an opensource project (libredwg)

I have the following code:

*offset = *(*src)++;

What does this do?

I understand

offset = *src++;

which would assign src[0] to the variable 'offset' and then increment src so that it points to what was previously src[1].

5 Years
Discussion Span
Last Post by davecoventry

You're already halfway there when it comes to understanding this line, then. For this code to make sense, src has to be a pointer to a pointer type, such as char**, and offset has to be a pointer type, such as char*.

What this particular line of code is doing is saying "Make the memory at the address pointed to by offset equal to the value at the address pointed to by *src (src itself being an address that points to that address), and then increment *src so it points somewhere else." It sounds like a mouthful, but that's how it works.

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.