What is the & doing in this instance?:
Particle.variable("analogvalue", &analogvalue, INT);
Sorry if this is a basic question. hopefully it’s an easy basic answer.
Thanks in advance!
What is the & doing in this instance?:
Particle.variable("analogvalue", &analogvalue, INT);
Sorry if this is a basic question. hopefully it’s an easy basic answer.
Thanks in advance!
&analogvalue is the address in memory where the number “analogvalue” lives. “&” is called an “address operator”.
Go take a look at this for more exciting reading about pointers and such.
Thanks!
There is a newer syntax available:
Particle.variable("analogvalue", analogvalue);
https://docs.particle.io/reference/device-os/firmware/photon/#particle-variable-
That is what I had been using, but I thought maybe I was doing something wrong because my value was always “536871936” when I would pass it from the Argon to the cloud. I wasn’t sure what I was doing wrong and I didn’t know what that was for. Thanks for the help. I’m going to keep working on it.
The ‘&
’ operator is used to get the memory address of a variable. This along with its counterpart ‘*
’ operator are the basis for using pointers in C. This article might help:
@TeraBull, one point overlooked is that the form: Particle.variable("analogvalue", &analogvalue, INT);
has been deprecated for a while now, replaced with Particle.variable("analogvalue", analogvalue);
where the type and pointer is inferred. Using the old form may explain your value problems.
I didn’t know that! Thanks. Both forms are shown in the docs, and I wondered why.
It looks like the example apps in the web IDE use:
Particle.variable("analogvalue", &analogvalue, INT);
I feel like it would be good to update the example apps in that case.
Thanks for the info @peekay123