Hi, I'm a beginner that is trying to learn to code, and I am working through the Simon Monk "Programming Arduino..." book and have ran across something that is not explained clearly to me in the "Parameters" section of the Functions chapter.
There is what looks like a variable being declared called int d. I don't see that d was defined anywhere, so I don't understand how a letter can be used as an integer.
I have attached a picture with the areas of question circled in red.
Functions have parameters, your function has one called d that is an int.
When you call the function, you supply the arguments which correspond one-to-one with the parameters, in this case you supply an integer for d, like 42 or an expression that ultimately is seen as an integer.
Simon prolly covers how arguments have some rules and flexibility.
No, that's just what someone chose as an identifier. She might as well have called it broccoli for all the meaning it conveys, that is to say a name other than d might have been better.
What you're confused about is functions and function input arguments.
The line
void flash (int numFlashes, int d)
is the declaration of a function named flash, which accepts two input arguments, both of which must be integers. With the function definition on Lines 15–24, your sketch will be able to use expressions such as flash(20, 250) — this will "call" (i.e., execute) the function flash, using the values 20 and 250 as input arguments.
In order for the function definition to perform any actions based on the values of the input arguments, the function declaration must specify variable names representing each input argument (as well as the data type for those variables).
Thus, the expression void flash (int numFlashes, int d) specifies that the variable name numFlashes will be used to refer to the first input argument, and the variable name d will be used to refer to the second input argument (the expression also requires both of the input arguments to be of the type int).
Therefore when the flash function is called using the expression flash(20, 250) , the value of numFlashes is set to 20, and the value of d is set to 250.
I think this is a good illustration of one reason why giving variables meaningful names is important. The name could be anything, why not make it mean something?