在 C 中使用逻辑运算符切换大小写 [英] Switch case with logical operator in C

查看:25
本文介绍了在 C 中使用逻辑运算符切换大小写的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是 C 新手,需要帮助.我的代码如下.

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

 #include<stdio.h>  
 #include<conio.h>  
 void main()
 {

  int suite=2;  

  switch(suite)
     {           
      case 1||2:
      printf("hi");

      case 3:
      printf("byee");

      default:
      printf("hello");
     }

  printf("I thought somebody");
  getche();
  }

我在 Turbo C 中工作,输出是 helloI thinksome.没有错误消息.

I am working in Turbo C and the output is helloI thought somebody. There's no error message.

请告诉我这是如何工作的.

Please, let me know how this is working.

推荐答案

case 1||2:

变为 true.所以它变成了 case 1: 但传递的值是 2.所以默认 case 被执行.之后你的 printf("I think someone"); 执行了.

Becomes true. so it becomes case 1: but the passed value is 2. so default case executed. After that your printf("I thought somebody"); executed.

这篇关于在 C 中使用逻辑运算符切换大小写的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆