How to resolve 'error: jump to case label [-fpermissive]' in c++?

Example:

int x = 10;
switch (x) {
    case 10:
        int y = 20;
        break;
    case 20:
        y = 30;
        break;
}

This error occurs because of crossing initialization of a variable in one case to another.

Solution:

Define variables before the `switch` or in a common block within the `switch`.


int x = 10;
int y;
switch (x) {
    case 10:
        y = 20;
        break;
    case 20:
        y = 30;
        break;
}

Beginner's Guide to C++