What does comma operator mean in a switch statement?

后端 未结 6 402
-上瘾入骨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 07:58

    FYI, today one may use the GCC case ranges extension when it is appropriate (which is not often) for similar results (only ranges are supported, not arbitrary lists of values).

    case 1 ... 5:
    case 'A' ... 'Z':
    

提交回复
热议问题