#include<iostream.h>
#include<windows.h>
void main()
{
double ll;
double mm;
double *a;
double *b;
int N=3;
int i;
if((a=(double*)malloc(N*sizeof(double)))=NULL)
{
cout<<"err"<<endl;
return;
}
if((b=(double*)malloc(N*sizeof(double)))=NULL)
{
cout<<"err"<<endl;
return;
}
cout<<" input ll: "<<endl;
cin>>ll;
cout<<endl;
cout<<"input mm: "<<endl;
cin>>mm;
cout<<endl;
a[0]=ll;
b[0]=mm;
for(i=1;i<N;i++)
{
a[i]=a[i]/i;
b[i]=b[i]*i;
}
cout<<a[0]<<" "<<b[0]<<endl;
free(a);
free(b);
}
两个if都要用双等号判断,不能用等号赋值,并且,这个判断其实是没有意义的。
是双等号啊,这个是判断是否有足够的内存分配的,应该没错吧
追答你的代码和我的代码是有区别的,仔细查看。
你的判断,是判断了一个(..=..)赋值等式是否为NULL,这个在不同编译器模式下会有不同的结果,严格应该在a=malloc之后,判断if(NULL==a)