Result: runtime error (SIGSEGV)
I've written the following code to count average. In my PC program works fine. But when I submit it into OJ, it shows
Result: runtime error (SIGSEGV)
What does it mean by Result: runtime error (SIGSEGV)?
What is the problem in my code?
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32
|
#include <iostream>
using namespace std;
int main()
{
int t,n;
int num[n];
cin>>t;
while(t--)
{
double sum=0;
cin>>n;
for(int i=0; i<n; i++)
{
cin>>num[i];
sum+=num[i];
}
cout.precision(2);
cout <<fixed<<sum/n<<endl;
}
return 0;
}
|
ProgGeek wrote: |
---|
What does it mean by Result: runtime error (SIGSEGV)? |
It's a
segmentation fault. It happens when your program tries to access memory in ways that are not allowed.
http://en.wikipedia.org/wiki/Segmentation_fault
ProgGeek wrote: |
---|
What is the problem in my code? |
You are using an uninitialized variable to set the length of the array.
Thanks a lot Peter87 (5640). :D
Topic archived. No new replies allowed.