使用感叹号'!'在C中 [英] Using Exclamation Marks '!' in C

查看:177
本文介绍了使用感叹号'!'在C中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在阅读参考书中的代码时遇到了涉及感叹号和整数的问题.

I have come across a problem involving exclamation marks and integers whilst reading a code in my reference book.

让我们说我已经声明了一个名为number的整数变量-int number = 0;

Let us say I have declared an integer variable named number - int number = 0;

然后我使用一个带有感叹号和number

I then use a while function involving an exclamation mark and number

while(!number)
{
    ...
}

我对此感到困惑,因为我不知道!number是什么意思,可能返回的结果是什么?我不确定是否可以使用它,但是正如我所说,我在书中看到了它.

I am confused with this because I do not know what does !number mean and what would be possible returned results? I am not sure if this can be used, but as I said, I saw it in my book.

因此,如果有人可以告诉我 !number是什么意思,它的评价是什么?

Therefore, it would be great if someone could tell me what does !number mean and what does it evaluate?

谢谢.

推荐答案

我们可以将!视为不接受. 因此,如果数字非零(正数或负数),则返回零. 如果为零,则返回1.

We can treat ! as not. So if a number is non-zero (either positive or negative) it returns Zero. If it is zero, it returns 1.

int i = 13;
printf("i = %d, !i = %d\n", i, !i);
printf("!0 = %d\n", !(0));

这篇关于使用感叹号'!'在C中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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