2

I had two different codes:

uint8_t buf[10];
writeSomeDataInto(&buf);
readSomeDataFrom(buf);

and it was working correctly, but then I realized that I was sendind the address of the buffer, not the buffer itself, and changed it to:

uint8_t buf[10];
writeSomeDataInto(buf);
readSomeDataFrom(buf);

and the result was exactly the same.

Why am I getting the same result? Is &buf and buf the same thing in this context? It is actually does not make sense to me that the compiler would allocate some space for the buffer pointer &buf address.

How is this different from the code below?

uint8_t * ptr;
writeDataInto(&ptr); //actually  sending the pointer of a pointer.
readDataFrom(ptr);

Comparing it also with pointer to functions such as "void myfunc(); //myfunc == &myfunc

I feel that I'm missing some concept about how C works.

Jabberwocky
  • 48,281
  • 17
  • 65
  • 115
João PGC
  • 31
  • 3

0 Answers0