关于stack around the variable “a” was corrupted问题
程序运行时出现这样的错误
“Run-Time Check Failure #2 - Stack around the variable 'a' was corrupted.”
代码:
#include <iostream>
using namespace std;
void paixu(double RPolar1,double RPolar2,double RPolar3,double RPolar4)
{
double a[4]={RPolar1,RPolar2,RPolar3,RPolar4};
int i,j;
double k;
for(i=0;i<4;i++)
{
for(j=0;j<4-i;j++)
{
if(a[j]>a[j+1])
{
k=a[j];
a[j]=a[j+1];
a[j+1]=k;
}
}
}
for( i=0;i<4;i++)
{
cout<<a[i]<<endl;
}
}
int main ()
{
paixu(2.1,5.1,8.1,3.1);
return 0;
}
我把尝试把main函数改成:
void main ()
{
paixu(2.1,5.1,8.1,3.1);
}
又成功运行,想问一下这里的原理