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].

Recommended Answers

All 2 Replies

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.

Brilliant!

Thanks very much. And lucidly explained, too...

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.