Switch case with logical operator in C

前端 未结 5 1944
借酒劲吻你
借酒劲吻你 2021-01-12 20:59

I am new to C and need help. My code is the following.

 #include  
 #include  
 void main()
 {

  int suite=2;  

  switch(suit         


        
5条回答
  •  难免孤独
    2021-01-12 21:17

    do this:

    switch(suite){
      case 1:/*fall through*/
      case 2: 
        printf("Hi");
    ...
    }
    

    This will be a lot cleaner way to do that. The expression 1||2 evaluates to 1, since suite was 2, it will neither match 1 nor 3, and jump to default case.

提交回复
热议问题