What is the name of the “-->” operator?(Stackoverflow)

Question:

After reading Hidden Features and Dark Corners of C++/STL on comp.lang.c++.moderated, I was completely surprised that it compiled and worked in both Visual Studio 2008 and G++ 4.4.

The code:

#include <stdio.h>
int main()
{
     int x = 10;
     while( x --> 0 ) // x goes to 0
     {
       printf("%d ", x);
     }
}

I‘d assume this is C, since it works in GCC as well. Where is this defined in the standard, and where has it come from?

Answer:

That‘s not an operator -->. That‘s two separate operators,
--
and >.

The condition code is decrementing x, while returning x‘s original (not decremented) value, and then comparing the original value with
0 using the > operator.

To better understand, the statement could be written as follows:

while( (x--) > 0 )
时间: 2024-08-24 05:07:59

What is the name of the “--&gt;” operator?(Stackoverflow)的相关文章

实战c++中的智能指针unique_ptr系列-- 使用std::unique_ptr代替new operator(错误:‘unique_ptr’ is not a member of ‘std’)

写了很多篇关于vector的博客,其实vector很便捷,也很简单.但是很多易错的问题都是vector中的元素为智能指针所引起的.所以决定开始写一写关于智能指针的故事,尤其是unique_ptr指针的故事. 这是个开始,就让我们使用std::unique_ptr代替new operator吧! 还是用程序说话: #include<iostream> int main() { while (true) int *x = new int; } 看下任务管理器中的内存: 此时使用智能指针unique

c++ operator

这篇博文是以前很久写的,贴在我的早期一个blog中,今天google一下,发现还真有不少人转载,可惜并不注明出处.那时觉得operator比较好玩.C++有时它的确是个耐玩的东东.operator它有两种用法,一种是operator overloading(操作符重载),一种是operator casting(操作隐式转换). 1.operator overloading C++可以通过operator 重载操作符,格式如下:类型T operator 操作符 (),如比重载+,如下所示 [cpp

C++中的new/delete与operator new/operator delete

new operator/delete operator就是new和delete操作符,而operator new/operator delete是函数. new operator(1)调用operator new分配足够的空间,并调用相关对象的构造函数(2)不可以被重载 operator new(1)只分配所要求的空间,不调用相关对象的构造函数.当无法满足所要求分配的空间时,则        ->如果有new_handler,则调用new_handler,否则        ->如果没要求不

C++ operator(重载操作符) 【转】

转自:http://www.cnblogs.com/xiangxiaodong/archive/2012/02/12/2348144.html operator是C++的关键字,它和运算符一起使用,表示一个运算符函数,理解时应将operator=整体上视为一个函数名. 这是C++扩展运算符功能的方法,虽然样子古怪,但也可以理解:一方面要使运算符的使用方法与其原来一致,另一方面扩展其功能只能通过函数的方式(c++中,“功能”都是由函数实现的).  一.为什么使用操作符重载?对于系统的所有操作符,一

C++ 中 new 操作符内幕:new operator、operator new、placement new

原文链接 一.new 操作符(new operator) 人们有时好像喜欢有益使C++语言的术语难以理解.比方说new操作符(new operator)和operator new的差别. 当你写这种代码: string *ps = new string("Memory Management"); 你使用的new是new操作符. 这个操作符就象sizeof一样是语言内置的.你不能改变它的含义,它的功能总是一样的.它要完毕的功能分成两部分.第一部分是分配足够的内存以便容纳所需类型的对象.

C++中的new、operator new与placement new

转:http://www.cnblogs.com/luxiaoxun/archive/2012/08/10/2631812.html new/delete与operator new/operator delete new operator/delete operator就是new和delete操作符,而operator new/operator delete是函数. new operator 调用operator new分配足够的空间,并调用相关对象的构造函数 不可以被重载 operator n

operator new

document by C++: 系统的有三个声明: throwing (1) void* operator new (std::size_t size); nothrow (2) void* operator new (std::size_t size, const std::nothrow_t& nothrow_value) noexcept; placement (3) void* operator new (std::size_t size, void* ptr) noexcept; 定

C++中operator关键字(重载操作符)

operator是C++的关键字,它和运算符一起使用,表示一个运算符函数,理解时应将operator=整体上视为一个函数名. 这是C++扩展运算符功能的方法,虽然样子古怪,但也可以理解:一方面要使运算符的使用方法与其原来一致,另一方面扩展其功能只能通过函数的方式(c++中,“功能”都是由函数实现的).  一.为什么使用操作符重载? 对于系统的所有操作符,一般情况下,只支持基本数据类型和标准库中提供的class,对于用户自己定义的class,如果想支持基本操作,比如比较大小,判断是否相等,等等,则

Python中的sorted函数以及operator.itemgetter函数

operator.itemgetter函数operator模块提供的itemgetter函数用于获取对象的哪些维的数据,参数为一些序号(即需要获取的数据在对象中的序号),下面看例子. a = [1,2,3] >>> b=operator.itemgetter(1)      //定义函数b,获取对象的第1个域的值>>> b(a) 2 >>> b=operator.itemgetter(1,0)  //定义函数b,获取对象的第1个域和第0个的值>&