Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/arrays/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Arrays 全局定义数组,但其参数稍后可用_Arrays_C - Fatal编程技术网

Arrays 全局定义数组,但其参数稍后可用

Arrays 全局定义数组,但其参数稍后可用,arrays,c,Arrays,C,我想使用一个从函数HashTableInit到printfhash的数组。所以,我对它进行了全局定义。但是数组的参数存在于函数HashTableInit中。我不想通过返回函数来获取数组,因为要使用return,我需要在printfhash中调用整个函数,这会干扰我的整个代码 void HashTableInit(int TableSize, int Key) { //Create a space for HashTable as given in variable TableSize struc

我想使用一个从函数
HashTableInit
printfhash
的数组。所以,我对它进行了全局定义。但是数组的参数存在于函数
HashTableInit
中。我不想通过返回函数来获取数组,因为要使用return,我需要在
printfhash
中调用整个函数,这会干扰我的整个代码

void HashTableInit(int TableSize, int Key) {
//Create a space for HashTable as given in variable TableSize
struct hashTableNode * HT[TableSize];
for (int i = 0; i < TableSize; i++) {
    HT[i] = (struct hashTableNode*) malloc(sizeof (struct hashTableNode));
    HT[i] ->Key = 0;
    HT[i] ->next = NULL;
}
void HashTableInit(int TableSize,int Key){
//为HashTable创建一个空间,如variable TableSize中所示
结构hashTableNode*HT[表大小];
for(int i=0;iKey=0;
HT[i]->next=NULL;
}

在这里,TableSize将在该函数执行后可用。但是如何使用参数全局定义数组。

如果它不是指针,则可以使用全局值声明变量。
但在你的例子中,它是一个指针变量。在赋值之前,你必须手动分配地址。因此,创建一个函数将值分配给指针变量是一个很好的做法。但是你可以分配数组和一个变量来全局存储数组大小。我希望这会对你有所帮助。

实际上,我在定点方面很弱。这总是会把我的程序搞砸。如果你有一个定义指针函数来获取哈希表值的例子。那么,我会很感激的。我从互联网上搜索过,但没有找到任何我能理解的东西。