You are not logged in. Please login at www.codechef.com to post your questions!

×

Why do I get a SIGSEGV?

Why I am getting a runtime error SIGSEGV in the problem? Where I am going wrong?

asked 20 Mar '13, 17:03

rudreshwar's gravatar image

1★rudreshwar
407192531
accept rate: 50%


101 Answers:

12345 ... 11next »

18

This is an error caused by an invalid memory reference or segmentation fault. The most common causes are accessing an array element out of bounds, or using too much memory.

Some things for you to try:

Make sure you aren't using variables that haven't been initialised. These may be set to 0 on your computer, but aren't guaranteed to be on the judge.

Check every single occurrence of accessing an array element and see if it could possibly be out of bounds.

Make sure you aren't declaring too much memory. 64 MB is guaranteed, but having an array of size [10000][10000] will never work.

Make sure you aren't declaring too much stack memory. Any large arrays should be declared globally, outside of any functions - putting an array of 100000 ints inside a function probably won't work.

link

answered 20 Mar '13, 17:05

admin's gravatar image

0★admin ♦♦
14.3k347483501
accept rate: 36%

life saver!

(06 Jul '16, 23:00) radeonguy2★

U can declare a array of size [10000][10000] globally . and it will not give sigsegv error

(18 Aug '16, 03:44) yb4singh4★

use static memory allocation ,not dynamic (y) this causes SIGSEVG error sometimes

link

answered 05 Jan '16, 15:18

archit910's gravatar image

4★archit910
58217
accept rate: 3%

//why i was getting SIGSEGV?? //for this question http://www.codechef.com/COQU2014/problems/DCQ1402 //please help n explain

for this solution http://www.codechef.com/viewsolution/5277974

link

answered 07 Nov '14, 17:01

thepranay14's gravatar image

2★thepranay14
1
accept rate: 0%

why do i get SIGSEV for the problem http://www.codechef.com/KAN14ROL/problems/ACM14KN3/

link

answered 25 Nov '14, 20:07

gokul95's gravatar image

2★gokul95
261
accept rate: 33%

link

answered 25 Nov '14, 20:08

gokul95's gravatar image

2★gokul95
261
accept rate: 33%

why am i getting sigsev for the solution at http://www.codechef.com/viewsolution/5601458

link

answered 15 Dec '14, 16:13

rishikeshfanse's gravatar image

1★rishikeshfanse
1
accept rate: 0%

because you are initializing array a of size 5 , whereas n can be very large , so you are trying to access invalid memory hence SIGSEGV

(15 Dec '14, 16:18) acodebreaker22★

can anyone help m why m getting SIGSEGV RUNTIME ERROR http://www.codechef.com/viewsolution/5940071

link

answered 19 Jan '15, 23:20

visght's gravatar image

0★visght
1
accept rate: 0%

You have assumed that size of the array is 100 while it is given in the question that size can be up to 10^6. So in your for loop you will be accessing array out of bounds.

(06 Feb '15, 07:32) drgn_hart2★

why di i get reutime error for given problem

include<stdio.h>

include<stdlib.h>

define size 65535

int main() { long n,k,j,t[size],i=0,count=0; scanf("%ld %ld",&n,&k); while(i<n) { scanf("%ld",&t[i]); printf("\n"); if(t[i]%k==0) count++; i++; } printf("%ld\n",count); }

link

answered 22 Jan '15, 10:06

vineeta1995's gravatar image

2★vineeta1995
1
accept rate: 0%

please help why do i get sigsegv in this code http://www.codechef.com/viewsolution/5988352

link

answered 25 Jan '15, 12:57

anmolnijhawan's gravatar image

1★anmolnijhawan
1
accept rate: 0%

You are creating character array of length of 50 to store the given string whose length can be equal to 50. Each character array used to store string("%s" format specifier) automatically adds null character('\0') in the end. So you actually need length+1 memory to store.

(06 Feb '15, 07:36) drgn_hart2★

why do i get SIGSEVG

link

answered 04 Feb '15, 12:31

nikkey's gravatar image

1★nikkey
1
accept rate: 0%

toggle preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported
  • mathemetical formulas in Latex between $ symbol

Tags:

×207
×160
×51

Asked: 20 Mar '13, 17:03

Seen: 80,821 times

Last updated: 21 Apr, 00:14