[英]I can't understand why my program is asking for pointer in the index of an array
I am writing a code to find the intersection of 2 arrays.我正在编写代码来查找 2 arrays 的交集。 With my
i
and j
iterators, the IDE is asking me to convert them to pointers or something.使用我的
i
和j
迭代器,IDE 要求我将它们转换为指针或其他东西。 I'm specifically getting a pointer-to-object error.我特别收到了一个指向对象的错误。
Also I can't really wrap my head around when and how to use pointers.我也无法真正理解何时以及如何使用指针。 I know what they are (kind of) but I don't understand when to use them.
我知道它们是什么(有点),但我不明白什么时候使用它们。
void arrIntersect(int fArr, int sArr, int fArrElem, int sArrElem)
{
int i, j, k;
int largeArrElem = (fArrElem > sArrElem)?fArrElem:sArrElem;
int unionArr[largeArrElem];
for (i = 0; i < largeArrElem; i++)
{
for (j = 0; j < largeArrElem; j++)
{
if (fArr[i] == sArr[j]) //Here the i and j say pointer to object//
{
for (k = 0; k < largeArrElem; k++)
{
unionArr[k] = fArr[i]; //Here the i says pointer to object//
}
break;
}
break;
}
}
for (k = 0; k < largeArrElem; k++)
{
printf("%d, ", unionArr[k]);
}
}
Hi your intersection function is not right.You must decrise the size of largArrElem and also you have to decrise the size of j.Now for your problem with the arrays did you try to to create them dynamicaly with malloc?Also if you did that i thing you must add " * " in parametres like: Hi your intersection function is not right.You must decrise the size of largArrElem and also you have to decrise the size of j.Now for your problem with the arrays did you try to to create them dynamicaly with malloc?Also if you did that i您必须在参数中添加“ * ”,例如:
void arrIntersect(int *fArr, int *sArr, int fArrElem, int sArrElem)
Use it, there will be no error -使用它,不会有错误——
void arrIntersect(int fArr[], int sArr[], int fArrElem, int sArrElem)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.