简体   繁体   English

运行时错误(SIGSEGV)

[英]Runtime Error(SIGSEGV)

I am new to coding.我是编码新手。 When I am submitting my code in codecheff its giving "Runtime Error(SIGSEGV)".当我在 codecheff 中提交我的代码时,它给出了“运行时错误(SIGSEGV)”。 I Don't know what's the problem please help.我不知道是什么问题请帮忙。 Thanks in advance.提前致谢。

int call(int *x, int m)
{
   int b[10], y, z;
   for(y = 0 ; y<m ; y++)
   {
      int sum = 0;
      z = *x;
      while(z>0) {
         sum = sum + z/5;
         z=z/5;  
      }
      b[y] = sum;
      x++;
   }

   for(y = 0 ; y<m ; y++)
      printf("\n%d", b[y]);
}

int main() 
{
   int n=0, i=0, a[10]; 
   scanf("%d", &n);
   for(i=0;i<n;i++){
      scanf("%d", &a[i]);
   }
   call(a, n);
   return 0;   
}

If you're getting SIGSEGV, it means you're trying to access memory in a segment your program does not have access to, or you're trying to access memory your program has access to in an invalid way.如果您收到 SIGSEGV,则意味着您正在尝试访问程序无法访问的段中的内存,或者您正在尝试以无效的方式访问您的程序可以访问的内存。

Your first course of action should be to use Valgrind or Dr. Memory, when you have a memory segmentation error like this.当您遇到这样的内存分段错误时,您的第一个行动方案应该是使用 Valgrind 或 Dr. Memory。

Based on your code, I'd assume you may be having a problem when n > 10 that is causing a buffer overrun in b and x.根据您的代码,我认为当 n > 10 导致 b 和 x 中的缓冲区溢出时,您可能会遇到问题。 If you named your parameters to something meaningful, it would be easier for us to solve.如果您将参数命名为有意义的东西,我们会更容易解决。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM