What's the difference between char and int in a switch case?

前端 未结 8 1700
别跟我提以往
别跟我提以往 2021-01-13 11:21

I started C++ recently and while learning switch case, I got this doubt.
What\'s the difference if I use int or char in the following code :
int Fav_Car;

8条回答
  •  南方客
    南方客 (楼主)
    2021-01-13 11:48

    Why does it happen? Because in your switch case, you use a char, not int.

    What is the difference between them?

    1 //int
    '1' // char 1
    "1" // string 1
    

    To use int

    int a;
    switch(a){
        case 1 :
    }
    

提交回复
热议问题