参数声明[]和*(阵列) [英] Parameter declaration [] and * (array)

查看:112
本文介绍了参数声明[]和*(阵列)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在函数定义形式参数之间,如:

Between formal parameters in a function definition, like:

void change (int *s)
{   
    s[0] = 42;
}

和另一个定义:

void change (int s[])
{   
    s[0] = 42;
}

他们是我假设,如 *(A + 0)相同同一个[0]

有没有理由preFER一个比另一个?请注意,preference涉及的编码风格。

Is there a reason to prefer one over the another? Please note, the preference pertains to coding style.

推荐答案

是的,他们是完全一样的。声明为阵列的所有功能参数被调节到相应的指针类型。

Yes, they are exactly the same. All function parameters declared as arrays are adjusted to the corresponding pointer type.

我个人preFER前者实际上使得它看起来像一个指针声明而这正是在这两种情况下。

Personally, I prefer the former which actually makes it look like a pointer declaration which is what it is in both cases.

这篇关于参数声明[]和*(阵列)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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