What is the & for in &analogvalue

argon
photon
Tags: #<Tag:0x00007f039af99508> #<Tag:0x00007f039af993c8>

#1

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!


#2

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


#3

Thanks!


#4

There is a newer syntax available:

Particle.variable("analogvalue", analogvalue);

https://docs.particle.io/reference/device-os/firmware/photon/#particle-variable-


#5

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.


#6

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:


#7

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


#8

I didn’t know that! :roll_eyes:Thanks. Both forms are shown in the docs, and I wondered why.


#9

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