int [] 和 int* 作为函数参数的区别 [英] Difference between int [] and int* as function arguments

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

问题描述

这是一道面试题:

int []int* 有什么区别,它们都是函数的输入参数.

What is difference between int [] and int*, all of them are input arguments to a function.

f(int a[] , int* b)

我的回答:

对于f(),它们具有相同的功能.第一个是a[]中第一个元素的开始位置.

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屋!

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