Very quick/simple question

I apologize for such a mundane question, but it has been while since I've coded. What does the following code do:
1
2
3
4
const BYTE* buff,	/* Data to be sent */
      BYTE d;
		
      d = *buff++;



I understand declaring buff as a BYTE pointer, and d as a byte, but ++ is throwing me.

Thanks!
The ++ part is incrementing buff by one (BYTE). The * is de-referencing the value to which buff pointed before incrementing.
Awesome, thank you!
I strongly recommend creating a test program for this and investigating the output:
1
2
3
4
5
6
7
8
int n = 10;

const int * buff = &n;
int d = 0;

std::cout << "buff = " << buff << " n = " << n << " d = " << d << std::endl;
d = *buff++;
std::cout << "buff = " << buff << " n = " << n << " d = " << d << std::endl;

Last edited on
I also recommend you don't write confusing code like that.

This code:
1
2
d = *buff;
++buff;

works just as well and is less confusing. Just because you can do it in 1 line doesn't mean you should.
Last edited on
Topic archived. No new replies allowed.