Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我不清楚子数组。
认为:A[3]={1,2,3}
A[3]={1,2,3}
1,2 和 3 可以单独成为 A 的子数组吗?
答案是肯定的。在 C 中,数组基本上是一个指针及其长度。
你可以这样做:
int A[3] = {1,2,3}; int * p1 = A; // or p1 = &A[0] int * p2 = A+2; // or p2 = &A[2];
现在您可以p1作为 2 个元素的数组 ( {1,2}) 和p21 个元素的数组 ( {3}) 进行操作,但您必须自己了解或记住有关子数组长度的信息。
p1
{1,2}
p2
{3}