The 2...5 used in pinmode() are the actual pins that the switches are wired to. The variables just happened to be named switch1, switch2... (which, by the way are TERRIBLE names. Names should mean something like "ResetSwitch" or "PowerSwitch"...)
I agree an array would be better but it would most likely take up as many lines
I bet it wouldn't and in any case the number of lines does not matter, it is the amount, efficiency and ease of understanding and maintenance of the code that matters
Seems you are new to C/C++ so here is the answer: switch is actually a reserved programming word (see switch...case) so we can’t use it for a variable name of course... use switch[b]es[/b] for example instead of switch
Replace int switch[4] ;withint switches[4] ;
Also change the loop() into
void loop() {
for (byte i = 0; i<4; i++) switches[i] = digitalRead(2+i);
..
At the bottom part I see that it says:
switch1 = digitalRead(2);
switch2 = digitalRead(3);
switch3 = digitalRead(4);
switch4 = digitalRead(5);
that means every switch is related one of your outputs
switch1 is equal to digitalRead(2)
switch2 is equal to digitalRead(3)
switch3 is equal to digitalRead(4)
switch4 is equal to digitalRead(5)