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


Please help in SIGABRT and INTSET

Can any one help me in identifying the error in this code and reason for this error SIGABRT?

Question Enormous Input test code INTSET ?

using namespace std;
int main()
 long long int n,k,i,a,co=0;
 long long int arr[n];
 for(i=0;i< n;i++)
 for(i=0;i< n;i++)
 delete[] arr;

asked 19 May '17, 19:10

sanket007's gravatar image

accept rate: 0%

converted to question 19 May '17, 22:10

vijju123's gravatar image

5★vijju123 ♦♦


Write header file correctly

(19 May '17, 19:59) hruday9684★

Header is correct but it is showing error as SIGABRT

(19 May '17, 20:41) sanket0071★

Please try to comment such one liners.

(19 May '17, 22:07) vijju123 ♦♦5★

You are getting SIGABRT because the argument to delete[] must be a pointer to some block of memory that can be deallocated. However, your array arr is declared as a constant size array, so it does not qualify and you get undefined behaviour.
But you might say that it is not a constant size array since its size is provided during runtime. Your array arr is actually what is called a variable length array. VLAs are not a part of the C++ standard, however the gcc compiler (under which your submission was made) allows it. So you don't get a compilation error and it works, but you cannot free that memory because it is treated by delete[] as a constant size array. Hope that made sense.
The fix is to change "long long int arr[n];" to "long long int *arr = new long long int[n];". Now arr is dynamically allocated which can be freed by delete[]. Or maybe just don't free the memory, it's only competitive coding :P


answered 20 May '17, 00:37

meooow's gravatar image

6★meooow ♦
accept rate: 48%

This undefined behaviour is the reason of half of my debugging troubles. Hard to figure out!

(20 May '17, 00:48) vijju123 ♦♦5★

Declare array outside the int main and try once,let me know if this doesn't work


answered 19 May '17, 22:53

hruday968's gravatar image

accept rate: 14%

Can't believe I didn't notice that. Your main function is supposed to return an int. add return 0 at the end of the function.


answered 19 May '17, 22:59

abdullah768's gravatar image

accept rate: 17%

edited 19 May '17, 23:02

toggle preview

Follow this question

By Email:

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



Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text]( "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

Question tags:


question asked: 19 May '17, 19:10

question was seen: 250 times

last updated: 20 May '17, 00:48