0

使用函数返回指针的主要原因是什么?基本上它返回指针值,但我们也可以通过指针返回值。

那么为什么我们需要函数返回指针呢?它是减少代码的大小还是其他?有没有我们使用函数返回指针的应用程序?

4

2 回答 2

2

Not sure what you are asking but yes? you could copy a 2Gb variable or an address to that variable that is orders of magnitude smaller. You tell me which is quicker/more efficient ;)

Here is a tutorial that explains their usage: C pointers Right off the bat it explains how it is easy to use numbers to lookup a safety deposit box so you can go access it.

without the ability to return pointers there would be no point to even having pointers at all. i.e. when you allocated memory for data, a function returns the pointer to its location. So without that you would never know were the memory you allocated is.

So I guess the functionality of returning pointers is arguably to allow the presence of pointers themselves?

于 2013-10-01T15:55:11.550 回答
0

One example, you can return a pointer to a value. Anyone who has that pointer can then change the value.

于 2013-10-01T15:55:17.713 回答