What exactly does "int duration = 0" and "int distance = 0" do?

Hello all.

I'm brand new with Arduino and I was wondering what the two terms:

int duration = 0;
int distance = 0;


Thanks for your help :slight_smile:

Declares the two variables to be integers that can go from -32768 to 32767, and sets them to 0.

Duration implies a time, in which case unsigned long might be a better choice as that is what millis() returns and you want consistent math.

They each allocate space for a named variable able to hold an integer value between -32,768 and 32,767 and set the value to zero

Depending where in the program the commands are placed the values will be accessible to the program to read or change or not by using the name of the variable

Note that the names have no meaning to the program and could equally well be tom and jerry

Alright, thank you both for your very precise and quick answers!

Now I can move on with my project :slight_smile: