直接创建指向数组的数组指针。 [英] Directly creating a array pointer to an array.
本文介绍了直接创建指向数组的数组指针。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我是C的新手。
创建一个数组,在每个索引处保存指向另一个动态大小数组的指针。
I'm new to C.
Create an array which holds at every index a pointer to another array of dynamic size.
int main()
{
unsigned int i , j;
int* array1[2];
int a1[] = {1,2,3};
int a2[] = {2,3};
array1[0] = a1;
array1[1] = a2;
for (i=0 ; i < 2; i++) {
printf("The value of array1[%d] = %d" , i , *array1[i]);
}
return 1;
}
array1的值[0] = 1
array1的值[1] = 2
但同样直接这样做会导致错误。
the value of array1[0] = 1
the value of array1[1] = 2
But similarly doing it directly ,Causing an error.
unsigned int* c[3];
c[0] = {0, 5, 4, 7}; // This Line Err`
c[1] = {0, 5, 4, 3, 2, 6, 7};
c[2] = {0, 5, 4, 3, 2};
导致错误:文件try.c line xx function main:`{'
之前的语法错误
为什么?
谢谢
Causing an error : file try.c line xx function main: syntax error before `{'
Why ??
thanks
推荐答案
{1,2,3} 只有在数组定义期间初始化时才允许使用code>语法。一般分配不允许这样做。
The {1, 2, 3}
syntax is allowed only when initializing during the array's definition. It is not allowed for general assignment.
这篇关于直接创建指向数组的数组指针。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文