Multi button function

Hi all I'm new to this so go easy on me.

At the moment I have three (going to add more) momentary switchs/buttons.

I am currently running them with separate denounce if statements to register a press and turn somthing on or off.

What I want to know is if it is possible to have a function alter a variable that is sent to it.

For example If I have a function called 'buttons' with one of its values being 'state'

So if I send buttons(variable_i_want_to_change)

How do I get the function to change the variable I sent to it no matter which variable I send(Oviosly taking type into account)

Is this even possible, hope it makes sense.

Thanks in advance.

If I understand you correctly, what you’re looking for is called pass-by-reference (as opposed to pass-by-value).

Here two articles about those:

For purist’s sake and so you don’t get the wrong idea, C doesn’t have pass-by-reference, it always passes by value, but in the case of reference, you’ll passing a pointer (by value) to the original variable.

Discussion about this in case you’re wondering. Passing value by reference in C and C++ - C++ Forum

Normally, it's the other way around. The function Returns a value to the caller.

btnPressed = getButton();

After that, one uses something like

if(btnPressed = 1)
{//Button 1 was pressed so do something


{ case 1: // Button 1 pressed
case 2: // Button 2 pressed

However, to answer your question: "How do I get the function to change the variable I sent to it", you use a pointer to the variable. The function then doesn't get the value of the variable passed, it gets the address of the variable passed. If it changes the Contents at that address, effectively the value of the passed variable is changed.

Thankyou both of you for your quick reply. I'm pretty sure that's exactly what I was after. I will give it a go.

Edit after your advise and knowing what to look for I found this.

Hopefully this will help if anyone else comes across this.