[solution] warning: this statement may fall through [- wimplicit fallthrough]) encountered during GCC compilation

When practicing the switch statement in Ubuntu, if break is not added in the case statement, the warning message will pop up, causing the program to fail to compile,

root@root:~/code$ g++ -Wall -W test_switch.c -o test_switch 
test_switch.c: In function ‘int main()’:
test_switch.c:13:10: warning: this statement may fall through [-Wimplicit-fallthrough=]
   13 |    printf("1\n");
      |    ~~~~~~^~~~~~~~~~~~~
test_switch.c:15:3: note: here
   15 |   case 3:
      |   ^~~~
test_switch.c:16:10: warning: this statement may fall through [-Wimplicit-fallthrough=]
   16 |    printf("3\n");
      |    ~~~~~~^~~~~~~~~~~~~
test_switch.c:18:3: note: here
   18 |   case 5:
      |   ^~~~

At this time, adding – W when compiling the code can shield the alarm, and the code can be compiled normally

root@root:~/code$ g++ -Wall -W test_switch.c -o test_switch -w

Read More: