c语言语法笔记一则

见程序段,这段是可运行的,欢迎补充。

# 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;
	}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值