void test(int* integers, int n) { ... }
void test(int* integers[], int n) { ... }
Run Code Online (Sandbox Code Playgroud)
有什么不同?它们都是指向 int 的指针,并且可以用作数组。例如,什么时候使用第一个?
int*是一个指向 的指针int。它不是数组,但它可能表示数组的起始地址(或数组迭代器 \xe2\x80\x94 数组内部的位置)。
int*[]是一个指针数组int(不是s数组int!)。因为我们处于函数参数的上下文中,所以可以有空括号(即未知大小的数组),这实际上使该参数成为指向 的指针int。
void test(int* integers)您的意思是“和”之间有什么区别吗void test(int integers[])?
作为函数参数,type arg[]、type arg[SIZE]和对于编译器来说实际上type* arg是相同的。type* arg
对于阅读你的代码的程序员:
\n\ntype arg[]给出一个提示,arg应该是一个代表数组起始地址的指针。
type arg[SIZE]给出一个提示,arg应该是一个指针,表示指定的数组的起始地址SIZE。请注意,编译器会忽略SIZE并且不执行任何边界检查。
| 归档时间: |
|
| 查看次数: |
6065 次 |
| 最近记录: |