c - 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;
}
解决方案
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;
}
在上面的代码中,您可以看到对您的功能的一些修复!
推荐阅读
- service - Angular: Asyncvalidator best practice
- bash - export not modifying global variables
- javascript - Discord.js v13 反应角色
- amazon-web-services - 恢复已删除的 AWS Sagemaker Jupyter Notebook
- javascript - 如何根据Vue.js中的其他选择从一个选择中禁用选择选项?
- django - Django / GeoDjango 在 Ubuntu / Dokku 上找不到 GDAL 库
- java - 试图解释一个检查网络连接的java嵌套循环
- customization - 移动应用程序上的 Acumatica-LotSerialNbrAttribute 屏幕
- python - 如何计算数据库列中的字段数?(不包括 NULLS,不包括它们)
- sql - 返回数据 2 年前同月前一周的日期范围