C语言中一元加(+)运算符的作用是什么? [英] What is the purpose of the unary plus (+) operator in C?

查看:503
本文介绍了C语言中一元加(+)运算符的作用是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在C语言中,编写类似以下内容是合法的:

In C, it's legal to write something like:

int foo = +4;

但是,据我所知,+4中的一元加号(+)是空操作.是吗?

However, as far as I can tell, the unary plus (+) in +4 is a no-op. Is it?

推荐答案

按照6.3.3.3中的C90标准:

As per the C90 standard in 6.3.3.3:

一元+运算符的结果是其操作数的.整体提升是 在操作数上执行.结果为提升类型.

The result of the unary + operator is the value of its operand. The integral promotion is performed on the operand. and the result has the promoted type.

一元+或-运算符的操作数应具有算术类型.

这篇关于C语言中一元加(+)运算符的作用是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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