Why when I use a static variable in switch case it gives errors: "initialization of" counter "is skipped by 'case' label", "initialization of" counter "is skipped by 'default' label"
int num = 1; switch (num) { case 1: static int counter = 0; cout << "COUNTER = " << counter; counter++; break; case 0: cout << "000"; break; default: cout << "Error"; break; } This error can be corrected by moving the static variable to the bottom, but why c ++ does not allow this situation.