Question on simple function program

Hello! I have this code from a function tutorial:

int i = 0;
int e;
void setup() {
  // put your setup code here, to run once:
  Serial.begin(9600);
}

void loop() {
  // put your main code here, to run repeatedly:
  e= isEven(i);

  Serial.print(i);
  Serial.print(": ");
  if( e==1){
    Serial.println("even");
  } else {

   Serial.println("odd");
  }
  i++;
  delay(500);
  
}



int isEven(int a){
  if( a % 2 == 0){
    return 1;
    
  } else {
    return 0;
  }
  
}

What I dont undertsand is what int i in e= isEven(i); does.
Also I dont understand what the int a is in the isEven function and what number it is to see if its even or not.

Well, true and false can also be written programmatically as 1 and 0 (1=true, 0=false), so the isEven() returns either a 1 or a 0, depending on if i is an even number or not. This also explains the reason e is an int, as it holds a single integer which is returned from the isEven function.

i starts out as zero, then increments with each loop.

The first time you call

e= isEven(i);

the function returns a "1", which is also true.

In the function, you are using a local variable, a, which is known only to the function. The first time a is referenced in the function, it has to be declared as an integer, just like the int i in the global declarations. When you call the function, you are providing an integer value, i, as the argument. The function then assigns the value of i to it's local copy, a.

For further explanation, see scope.

Ahh, yeah, so a is the number you're testing, so all this program does is it uses the mod function which, incase you didn't already know, returns the remainder of the first number, divided by the second. e.g. if a = 5, then a % 2 gives 1 (the remainder).