见程序段,这段是可运行的,欢迎补充。
# include <stdio.h>
# include <math.h> //floor(), must be in C++
# include <stdlib.h> //rand()
double correlation_length[2];
char A[]="123";
//double *object;
//object=A; //cannot convert from char to double
struct ooo{
double A2[2][2]; //dimensions cannot be empty
int k;
char c3[10]; //dimensions cannot be empty
};
struct ooo test3(int ob1){
struct ooo ob2;
ob2.A2[0][0]=0.0;
ob2.k=ob1;
ob2.c3[0]='a'; //cannot be c3="a char"
return ob2;
}
int test(void){
char *A="aaa"; //not char[] a; not 'a'
char AA[2][3]={"1","2"}; //cannot be AA[2][]
// AA[0]="here";
// AA = "t"; wrong
// AA={'1','2'}; wrong
A="aa1";
printf("%c\n", A[2]); //1
printf("%d\n", *A); //97(the ascii of first letter)
//printf("%s\n", *A); //wrong
printf("%s\n", A); //aa1
double *d10;
//d10=&rand(); //error
//*d10=rand(); //runtime error
double dran=20;
d10=&dran;
printf("%f\n",*d10); //* is a must
double d1=rand();
// int r1=(int)d1;
//double r2=floor(d1); //error in c, so is round
double dd[3][2];
//double d1[2]; //redefinition
//d1[0]=1;
//d1[1]=2;
//dd[0]=d1; wrong
double d11=1.0;
double *tt1;
//double *object=&d11;
double o[3];
o[0]=1.0;
o[1]=2.0;
o[2]=3.0;
double *object;
//*object=d11;
object=&d11;
//printf("%f\n",object); //because object is a pointer, not double
printf("%f\n",*object); //1.000000
*object=d11;
printf("%f\n",*object); //1.000000
object=o;
printf("%f\n",object[0]); //1.000000
double oo[3][2];
oo[0][1]=2;
oo[1][0]=1;
object=oo[0]; //object=oo: wrong. can be only one layer
printf("%f\n",object[1]); //2.000000
//*object=d1;
//tt1=test2(*object); //reference to another function will cause error
return 0;
}
//double *tt1;
// tt1=test2(object);
double *test2(double *oo[]){ //*test2[]:wrong
double *t2[3];
int i;
for(i=0;i<3;i++){
t2[i]=oo[i];
}
return t2[0];
}
int main(void){
double i=1;
double *object[3];
object[0]=&i;
object[1]=&i;
object[2]=&i;
double *tt1;
tt1=test2(object);
//printf("%f\n",tt1); //%d means "int"; error; must put a * before tt1
printf("hi\n");
printf("%f\n",*tt1); //1.000000
test();
struct ooo obj1=test3(10); //10
printf("%d\n",obj1.k);
return 0;
}