回答
不,两者没有区别。
你将不得不取消引用值第一个...
我.......认为 – 2011-03-30 20:19:09
nope。这取决于你,如果你愿意,你可以解引用第二个:'*(array + 3)'和'pointer [3]'是一样的。 – BlackBear 2011-03-30 20:21:36
那么,我有两个函数: int function(int arr []); int function2(int * arr); 为了测试,我有这个数组: int arr [5] = {1,1,1,1,1}; 在Visual Studio 2010中,我可以这样做: function(arr); function2(arr); 即使我没有将一个动态分配的数组传递给function2,它仍然允许我这样做。为什么是这样?通过做基准测试,两个函数都有相同的结果,所以如果解除引用确实发生,它可以忽略不计。 – leetNightshade 2011-03-30 20:26:24
语义是相同的,但对于外部编程,它更容易和直接的理解:第二个函数接受一个数组作为参数。它不可能像第一个那样直接。
C编译器没有区别。尽管如此,读取代码的程序员却有所不同。
这里,ARR是指向一个整数(可能用于从函数返回的结果):
foo(int* arr) {}
这里,ARR是一个指向第一个整数数组中的(可能是用于使列表在功能中和/或在功能外):
foo(int arr[]) {}
此外,指定函数的返回类型将有所帮助。
- 1. func foo(arr [] int)int和func foo(arr [num] int)有什么区别int
- 2. 代码崩溃时INT ARR = 1 && arr;但不是INT ARR = 0 && arr;
- 3. jQuery的$。每个(ARR,FOO)与$(ARR)。每个(富)
- 4. 类foo,类foo()和类foo(object)之间的区别?
- 5. 作为参数($ foo)和(foo $ foo)之间的区别
- 6. “struct foo *”和“foo *”之间的区别foo是一个struct吗?
- 7. static_cast <int>(foo)vs.(int)foo
- 8. Scala如何知道“def foo”和“def foo()”之间的区别?
- 9. JavaScript:Reflect.get()和obj ['foo']之间的区别
- 10. [foo release]和self.foo = nil之间的区别;
- 11. Angular 4中[(ngModel)] =“foo”和#foo之间的区别?
- 12. ifeq($(foo),)和ifndef foo之间的区别是什么
- 13. “virtual void IBase :: Foo”和“virtual void Foo”之间的区别是什么?
- 14. 为什么int * arr = {};法律?
- 15. PHP:{$ foo}和$ {foo}之间是否有区别
- 16. 在Backbone中,model.get('foo')和model.attributes.foo之间的任何区别?
- 17. int foo = foo的标准参考
- 18. 这是什么意思? int foo = foo + 4;
- 19. int p = *(int *)i和int p = *(int *)&i之间的区别
- 20. Foo :: class.java和Foo :: javaClass有什么区别?
- 21. 三星:char *(* arr)[]和char *** arr(在C中)有什么区别?
- 22. int someInts [3]和int * someInts = new int [3]之间的区别?
- 23. int x; arr [100]是什么意思?
- 24. 语法“Foo(int v):val_(v){}”?
- 25. uint和unsigned int之间的区别?
- 26. C#中char和int之间的区别#
- 27. Python 3.5 - '//'和'int()'之间的区别
- 28. int,NSInteger和NSUInteger之间的区别
- 29. PHP中(int)1和1之间的任何区别?
- 30. Java中的int a [5],int a [],int a [] = {2,3}之间的区别
哇 - 今天很多这种类型的问题! – Sadique 2011-03-30 20:30:16
相关,但更新,问题:http://stackoverflow.com/questions/5573310/difference-between-passing-array-and-array-pointer-into-function-in-c – jogojapan 2013-05-25 09:34:21