首页 > 解决方案 > C:加载'int'类型的空指针(__Serializer__.c),我的代码出错

问题描述

我针对上述问题的代码收到以下运行时错误“第 207 行:字符 3:运行时错误:加载 'int' 类型的空指针(Serializer .c)”关于我做错了什么的任何建议。我的代码:

int* twoSum(int* nums, int numsSize, int target, int* returnSize)
{
    int x=0,i,j;
    returnSize = (int*)malloc(2 * sizeof(int));
    for (i=0; i<numsSize; i++)
        {
        x = nums[i];
            for (j=i+1; j<numsSize; j++)
            {
             if (nums[j] == target-x)
                {   
                    returnSize[0] = i;
                    returnSize[1] = j;
                    break;
                }
            }
        }
   return *returnSize;
}

标签: c

解决方案


int* twoSum(int *nums, int numsSize, int target, int* p_retval_size)
{
int x=0,i,j;
int* p_retval = NULL;

/*check inputs*/
if(!nums || numSize < D_SOME_PREDEFINED_VALUE || !(p_retval = (int*)malloc(2 * sizeof(int)))
{
    *p_retval_size=0;
    return p_retval;
}

/*do the function work */

*p_retval_size = 2;
return p_retval;
}

在上面的代码中,您可以看到对您的功能的一些修复!


推荐阅读