switch

can we declare a variable inside switch block and if we then how
closed account (1vRz3TCk)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
#include<iostream>

using namespace std;

int main()
{
    int num =3;

    switch(num)
    {
    case 0:
        int v = 4;  // this will give an error
        // ...
        break;
    case 1:
        {              
            int q = 5;  //inside a block is OK
            // ....
        }
        break;
    default:
        //...
        break; 
    }
}
Last edited on
i want to use that variable just outside that switch block
closed account (1vRz3TCk)
Then you would have to declare the variable prior to entering the switch block.
Topic archived. No new replies allowed.