What does comma operator mean in a switch statement?

后端 未结 6 406
-上瘾入骨i
-上瘾入骨i 2021-01-17 07:31

I was given a question and was asked to give the output.

int main(void){  
    int x = 2;  
    switch(x){  
        case 1,2,1: printf(\"Case 1 is executed\         


        
6条回答
  •  被撕碎了的回忆
    2021-01-17 08:18

    You can not use twice the same 'case' value
    This is not correct: case 1: case 2: case 1: printf("Case 1 is executed");
    Tried to compile on VS2010 => (error C2196: case value '1' already used)

提交回复
热议问题