什么是&功放;&功放;&安培;在C温度范围 [英] What is &&& operation in C

查看:99
本文介绍了什么是&功放;&功放;&安培;在C温度范围的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

#include <stdio.h>

volatile int i;

int main()
{
    int c;

    for (i = 0; i < 3; i++) 
    {
         c = i &&& i;
         printf("%d\n", c);
    }

    return 0;
}

使用 GCC编译上述程序的输出

0
1
1

随着 -Wall -Waddress 选项, GCC 发出警告:

warning: the address of ‘i’ will always evaluate as ‘true’ [-Waddress]

如何 C 在上面的程序进行评估?

How is c being evaluated in the above program?

推荐答案

这是 C = I和;&安培; (安培; I); ,与第二部分是多余的,因为&放大器;我将永远不会计算为

It's c = i && (&i);, with the second part being redundant, since &i will never evaluate to false.

对于用户定义类型,在这里你可以真正重载一元运营商和放大器; ,它可能是不同的,但它仍然是一个非常糟糕的主意

For a user-defined type, where you can actually overload unary operator &, it might be different, but it's still a very bad idea.

如果您上的警告反过来后,你会得到这样的:

If you turn on warnings, you'll get something like:

警告:'我'的计算结果始终为地址真正的

warning: the address of ‘i’ will always evaluate as ‘true’

这篇关于什么是&功放;&功放;&安培;在C温度范围的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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