简体   繁体   English

我不明白为什么我的程序在数组的索引中要求指针

[英]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.使用我的ij迭代器,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.

相关问题 不明白为什么C程序崩溃,字符串的指针数组 - Don't understand why C program crashes, pointer array of strings 我不明白为什么我的数组产生我无法使用的输出 - I don't understand why my array produces output I can't use 指向字符指针的指针,或者为什么不能重新分配此数组? - Pointer to a pointer of a character pointer, or why can't I reassign this array? 我不明白为什么我的阵列大小不正确 - I can't understand why i have the wrong size of my array 无法理解指向固定大小数组的指针 - Can't understand a pointer to a fixed size array 我不明白为什么我的气泡排序没有显示第二个数组花费的任何时间 - I can't understand why my bubble sort is not showing any time taken for the second array 为什么我不能访问数组中指向我的成员函数的指针? - Why can't I access the pointer to my member function in my array? 为什么我不能将2D数组作为指针传递给指针,却可以将1D数组作为指针传递给 - Why can't I pass a 2D array as a pointer to pointer but can pass a 1D array as a pointer 我收到此错误,但我不明白为什么:子脚本值既不是数组也不是指针也不是向量| - I receive this error and I can not understand why: sub scripted value is neither array nor pointer nor vector| 如何退出程序,要求在数组中输入? - How can I exit a program asking for inputs in an array?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM