Switch case with logical operator in C

前端 未结 5 1936
借酒劲吻你
借酒劲吻你 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:26

    case (1||2):
      printf("hi");
    

    Just put brackets and see the magic.

    In your code,the program just check the first value and goes down.Since,it doesn't find 2 afterwards it goes to default case.

    But when you specific that both terms i.e. 1 and 2 are together, using brackets, it runs as wished.

提交回复
热议问题