What does & mean or do?

in the statement

"Particle.variable(“analog”, &getvalue, INT);

what does the & mean or do?

thanks steve

The ampersand is the “address of” operator in C. It means that you are passing the address of the variable, getValue, into the method, rather than its value. However, this is old syntax, and you shouldn’t be using it any more.

I always use this reference page when coding which has been very helpful for me personally when basic programming questions come up.

https://www.arduino.cc/reference/en/

why would I want to do that?

s

thanks that looks very helpful

Why would you want to do what?

1 Like

why would I want to pass the address rather than its value? the only thing I can think of if a value is assigned it will stay that way until it is reassigned but if the address is assigned then if the value changes mid cycle it will change. is that right?

basically why assign an address?

s

That is a fundamental question whether you need to pass the variable by value or by reference - in the first place.
If you think of it when you call Particle.variable(). That function is only called once in setup() so are you really interested in the value getvalue would have there and then (=by value) or would not rather want to know what the value is whenever it changes somewhere in your code (=by reference).

Exacty the other way round. (Usually) The address of a (global or static) varible will stay the same as long the program runs but the value stored at this location will change over time. If you pass a variable by value, the value gets “detached” from the variable and won’t change no matter what to the original variable happened.

This calls for some googling for “by reference vs. by value”

1 Like

thanks all ya’ll i am making progress I am smarter than I was yesterday.

another question, How much current will a DIP carry? Can I use it to turn on and off my proton?

thanks steve

What do you mean by DIP - I’d understand a Dual In-line Package and since there are litterally thousands of devices that feature that kind of package, what answer do you expect?

DIP switch

OK, in that case - but in all other possible DIP devices just the same - the datasheet of the specific item would be the source for the final word.
But AFAIK “standard” DIP switches are available from ~20mA to ~400mA ratings but there might be even higher rated versions.
Whether 400mA will be enough or not depends on your entire setup and use-case.

Thanks, btw your ds18d20 library works flawlessly. Thanks for your help

Is there a c++ reference text you would recommend

S

If you like books I’d recommend this:

It’s pretty handy for when you know something exists but you forget how to do it.

This site is a good resource for general c++:
http://www.cplusplus.com

And of course the Particle Documentation is superb as well:
https://docs.particle.io/reference/firmware/

1 Like

thank you