And*_*Sun 11 c arrays pointers
假设我有一个函数,它接受一个结构数组,定义如下:
void Foo(struct MyStruct *s, int count) {
for (int i = 0; i < count; ++i) {
// Do something with s[i]
}
}
Run Code Online (Sandbox Code Playgroud)
以下两个片段是否保证以相同的方式运行?
struct MyStruct s;
s.x = 0;
s.y = 0;
Foo(&s, 1);
Run Code Online (Sandbox Code Playgroud)
与
struct MyStruct s[1]; // stack-allocated array of size 1
s[0].x = 0;
s[0].y = 0;
Foo(s, 1);
Run Code Online (Sandbox Code Playgroud)