I don't understand some old C array concatenation

I do not understand this syntax in this old program C, and I am not configured to check the code to see what it does. The part I'm confused with is the concatenation of the array. I did not think that C could handle automatic typing, or I find it difficult in my head that on Friday afternoon ...

char wrkbuf[1024];
int r;
//Some other code
//Below, Vrec is a 4 byte struct
memcpy( &Vrec, wrkbuf + r, 4 );

Any idea what will be here? What does it mean wrkbufwhen you combine or add an int to it?

+3
source share
2 answers

wrkbuf + r coincides with &wrkbuf[r]

wrkbuf wrkbuf + 4 "" . r, r. .. , .

memcpy( &Vrec, wrkbuf + r, 4 ); 4 wrkbuf, r th Vrec

+4

memcpy(&Vrec, wrkbuf + r, 4) 4 r - wrkbuf Vrec. int , r -th , &wrkbuf[r].

memcpy C ( , strcpy):

void *
memcpy (void *destaddr, void const *srcaddr, size_t len)
{
  char *dest = destaddr;
  char const *src = srcaddr;

  while (len-- > 0)
    *dest++ = *src++;
  return destaddr;
}

:

+2

Source: https://habr.com/ru/post/1790072/


All Articles