×

# Why am I getting a segmentation error on this?

 0 I am pretty new to programming, so please ignore the inefficiency of the program. This is a program to arrange numbers in increasing order, and it runs perfectly in code::blocks, but submitting this as an answer to one of the practice problems gives a segmentation error. Language is C++. #include signed int a[100000]; int main() { int t=0,num=0; scanf("%d%",&t); for(int i=0;i<100000;++i) { a[i]=-1; } for(int j=0;j

 1 Each line contains one integer: N [0 <= N <= 10^6] Just change the size of the array. answered 29 Jul '14, 08:34 3★gautam94 474●14●26●46 accept rate: 11%
 0 Thanks... I did both, changed array size and declared loop variables outside, don't know which but one worked. answered 29 Jul '14, 13:36 6★c1_6 81●1●10 accept rate: 0% Declaring loop variables inside the loop does not cause runtime error. (29 Jul '14, 13:42) gautam943★
 -1 I did not got any segmentation fault on gcc compiler. Just try to declare the loop variable declarations outside the loop. answered 29 Jul '14, 12:25 0★rajatsr 0 accept rate: 0%
 toggle preview community wiki:
Preview

By Email:

Markdown Basics

• *italic* or _italic_
• **bold** or __bold__
• 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:

×1,911
×23

question asked: 29 Jul '14, 03:18

question was seen: 1,060 times

last updated: 29 Jul '14, 13:42