c语言编程中的"或"逻辑的符号 符号如何输入,C语言中逻辑运算符(&&,||,!)和位运算符号(&,|,^)...

1. C语言中逻辑运算符(&&,||,!)和位运算符号(&,|,^)的区别

在C语言中,编程者经常混淆两组运算符:(&&,||,!)和(&,|,^)。第一组是逻辑运算符,它的操作数是布尔型,而第二组则是位运算符,其操作数是位序列。在布尔型操作数中,只有两个数值,0或1。C语言规定,在逻辑运算中,所有的非0数值都看做1处理。而位序列则可以是有无符号的字符型,整型,长短整型等。在位运算中,是相应的位之间进行逻辑运算。因此,从逻辑上讲,位运算过程包含多个逻辑运算过程。通常,位运算操作数选择无符号型数据。

1.1. 应用实例

#include

int main(int argc, char

*argvs[])

{

unsigned int a = 0x11;

unsigned int b =

0x00;

unsigned short s =

0x10;

unsigned char c =

0x01;

if(a&&b) printf(“True: a

&& b is %d \n”,

a&&b);

else printf(“False: a

&& b is %d \n”,

a&&b);

if(a&&s) printf(“True: a

&& s is %d \n”,

a&&s);

else printf(“False: a

&& s is %d \n”,

a&&s);

if(a&&c) printf(“True: a

&& c is %d \n”,

a&&c);

else printf(“False: a

&& c is %d \n”,

a&&c);

if(s&&c) printf(“True: s

&& c is %d \n”,

s&&c);

else printf(“False: s

&& c is %d \n”,

s&&c);

printf(“a & b is

%x \n”, a&b);

printf(“a & s is

%x \n”, a&s);

printf(“a & c is

%x \n”, a&c);

printf(“s & c is

%x \n”, s&c);

printf(“a &

0x110 is %x \n”, a&0x110);

return 0;

}

执行结果是:

False: a

&& b is 0

True: a

&& s is 1

True: a

&& c is 1

True: s

&& c is 1

a & b is

0

a & s is

10

a & c is

1

s & c is

0

a & 0x110 is

10

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值