0

I am writing one sample c++ program , but while initializing the variable inside the switch case it gives me compilation error.

if i am declaring it like int x; its not giving the error, same is happening when i am doing it inside a case block also.

#include <iostream>

using namespace std;

int main()
{
    int x=3;
   switch(x)
   {
       int y=10;
       case 2:
          cout<< "c++";
   }
}

this gives me error like error: jump to case label [-fpermissive]

can anybody clarify my doubts

  • Googling the error message lands you [at this S.O. question](https://stackoverflow.com/q/5685471/831878). Does that help or do you need further clarification? – Ray Toal Oct 29 '17 at 04:11
  • In case anyone lands here: the question that this was marked a duplicate of is slightly different. In that question, the variable was declared after a case label. In this case, the variable declaration was not inside of any case. It's an error either way, but the error message is different. – Ray Toal Oct 29 '17 at 04:14
  • use { and } after case : – sam Oct 29 '17 at 07:11

0 Answers0