INT []和INT *作为函数参数的区别 [英] Difference between int [] and int* as function arguments
问题描述
这是一个面试问题:
什么是 INT []的区别
和为int *
,所有的人都输入参数的函数。
What is difference between int []
and int*
, all of them are input arguments to a function.
f(int a[] , int* b)
我的回答:
有关 F()
,它们具有相同的功能。第一个是第一个元素的起始位置的[]
。
For f()
, they have the same functions. The first one is the beginning position of the first element in a[]
.
第二个指向一个 INT
。
但是,如何在不经过其他参数相互区别开来?
But, how to distinguish them from each other without passing other arguments ?
推荐答案
作为函数的参数,这两种类型是完全一样的, INT []
改写为为int *
,你不能区分它们。在StackOverflow上很多很多问题涵盖了这个问题,并且 C-FAQ 甚至有一个的的指针和数组的特殊部分(作为参数与否)。看看进去了。
As function parameters, the two types are exactly the same, int []
is rewritten to int *
, and you can't distinguish between them. Many many questions in StackOverflow cover this subject, and the c-faq even has a special section on pointer and arrays (as arguments or not). Take a look into it.
这篇关于INT []和INT *作为函数参数的区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!