C ++ * VS []作为函数参数 [英] C++ * vs [] as a function parameter

查看:113
本文介绍了C ++ * VS []作为函数参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

之间有什么区别:

void foo(item* list)
{
    cout << list[xxx].string;
}

void this(item list[])
{
    cout << list[xxx].string;
}

假设产品:

struct item
{
    char* string;
}

随着指针指向第一个字符数组

With the pointer pointing to the first of an array of chars

列表只是一个项目数组...

and list is just an array of items...

推荐答案

要编译器,没有任何区别。

To the compiler, there is no difference.

它读取不同的东西。 [] 建议你要到一个数组传递给函数,而 * 也可能意味着只是一个简单的指针。

It reads different though. [] suggests you want to pass an array to the function, whereas * could also mean just a simple pointer.

请注意,当作为参数传递,数组衰变为指针(在你不知道的情况下)。

Note that arrays decay to pointers when passed as parameters (in case you didn't already know).

这篇关于C ++ * VS []作为函数参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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