出现 “已触发了一个断点” 情况

#include <stdlib.h>
#include<math.h>
int* decode(int* encoded, int encodedSize, int first, int* returnSize)
{
    int i = 1;
    int count = encodedSize + 1;
    int* ret = returnSize;
    returnSize[0]= first;
      // returnSize++;

      while (i<count)
      {
          returnSize[i] = abs((returnSize[i-1] - encoded[i-1]));
          i++;
      }
    return ret;
}

int main()
{
    int encoded[] = { 1, 2, 3 };
    int first = 1;
    int encodedSize = sizeof(encoded) / sizeof(encoded[0]);
    int count = encodedSize + 1;
    int * returnSize = (int *)malloc(sizeof(char) * (count));
    returnSize=decode(encoded, encodedSize, first, returnSize);
    if (returnSize == NULL)
    {
        exit(0);
    }
    for(int i = 0; i < count; i++)
        printf("%d ", returnSize[i]);
    
    free(returnSize);
    return 0;
}

 

int * returnSize = (int *)malloc(sizeof(char) * (count));这句话有问题,你申请的是int*,但是用的是sizeof(char),这是错误的,应该是:

int * returnSize = (int *)malloc(sizeof(int) * (count));

如有帮助,请采纳一下,谢谢。