简体   繁体   English

在 function (C) 中用作 arrays 的指针

[英]Pointers used as arrays in function (C)

test(int arr[]) and test(int *arr) are equivalent expressions. test(int arr[])test(int *arr)是等价的表达式。

So I want to ask what applies to test(int **ar) ?所以我想问什么适用于test(int **ar)

update:更新:

I need to call in main the function test(int *k,int **c) and I can't understand what values are transferred from the main to test.我需要调用主要的 function test(int *k,int **c) ,我无法理解从主要传输到测试的值。

For example if I had two arrays K[3] and C[24] and I wanted to use these two as parameters I would call in main as test(K,C);例如,如果我有两个 arrays K[3]C[24]并且我想使用这两个作为参数,我会在 main 中调用test(K,C); and the function would be declared as void test(int k[ ],int c[ ]);并且 function 将被声明为void test(int k[ ],int c[ ]);

In this example k[0]=K[0] , k[1]=K[1] , k[2]=K[2] , k[3]=K[3] and c[0]=C[0] .. c[24]=C[24] etc.在这个例子中k[0]=K[0] , k[1]=K[1] , k[2]=K[2] , k[3]=K[3]c[0]=C[0] .. c[24]=C[24]

So I want to understand in function test(int *k,int **c) what happens with the values of the parameters所以我想在 function test(int *k,int **c)中了解参数值会发生什么

Quote from N1570 6.7.6.3 Function declarators (including prototypes):引用N1570 6.7.6.3 Function 声明符(包括原型):

7 A declaration of a parameter as ''array of type'' shall be adjusted to ''qualified pointer to type'' 7 将参数声明为“类型数组”应调整为“限定类型指针”

int **ar is "a pointer to int* , so "an array of int* " int *ar[] will be adjusted to that when it is used as a function argument. int **ar是“指向int*的指针,因此“一个int*数组” int *ar[]将被调整为当它用作 function 参数时。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM