c++ - 请问这是什么语法2["abc"]?
高洛峰
高洛峰 2017-04-17 15:04:46
0
4
502

cout<<2["abc"]<<endl;
输出c。
不过这是什么语法啊,c++/c的,以前没遇到过,百度无果,有没有老司机带带啊。

高洛峰
高洛峰

拥有18年软件开发和IT教学经验。曾任多家上市公司技术总监、架构师、项目经理、高级软件工程师等职务。 网络人气名人讲师,...

reply all(4)
伊谢尔伦

a[b] is actually *(a + b)
so the above code is equivalent to

#include <iostream>

using namespace std;

int main(void) {
    cout << *("abc"+2) << endl;
    return 0;
}

Move a stackoverflow: http://stackoverflow.com/ques...

迷茫

This example is mentioned on page 144 of "C and Pointers", so I will just screenshot it for you. The author does not recommend writing it this way.

Peter_Zhu

Please ask the question under what circumstances did you encounter this problem? I'm a little curious about what this is.

洪涛

Is this a mapping table?

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!