- AnalogWeakTypeParameter.c
- 运行结果示例
【TDTX】 AnalogWeakTypeParameter.c
#include#include typedef struct Object { int sym[13];//赋值使用标记,每次对Object ob赋值时,使其只具有唯一数据类型使用 char *chp;//sym[12] char ch;//sym[0] short st;//sym[1] int a;//sym[2] bool bol;//sym[3] long b;//sym[4] long long lg;//sym[5] float c;//sym[6] double d;//sym[7] char s[1000];//sym[8] enum em { sun };//sym[9] union un { char chh; short stt; int aa; long bb; long long lgg; float cc; double dd; };//sym[10] struct objecT { };//sym[11] }Object; void print(Object object,bool hh) { if(object.sym[0] == 1) { if(hh == 0) { printf("%c",object.ch); } else { printf("%cn",object.ch); } return; } if(object.sym[1] == 1) { if(hh == 0) { printf("%d",object.st); } else { printf("%dn",object.st); } return; } if(object.sym[2] == 1) { if(hh == 0) { printf("%d",object.a); } else { printf("%dn",object.a); } return; } if(object.sym[3] == 1) { if(hh == 0) { if(object.bol == 1) { printf("true"); } else { printf("false"); } } else { if(object.bol == 1) { printf("truen"); } else { printf("falsen"); } } return; } if(object.sym[4] == 1) { if(hh == 0) { printf("%ld",object.b); } else { printf("%ldn",object.b); } return; } if(object.sym[5] == 1) { if(hh == 0) { printf("%lld",object.lg); } else { printf("%lldn",object.lg); } return; } if(object.sym[6] == 1) { if(hh == 0) { printf("%f",object.c); } else { printf("%fn",object.c); } return; } if(object.sym[7] == 1) { if(hh == 0) { printf("%lf",object.d); } else { printf("%lfn",object.d); } return; } if(object.sym[8] == 1) { if(hh == 0) { printf("%s",object.s); } else { printf("%sn",object.s); } return; } if(object.sym[12] == 1) { if(hh == 0) { printf("%s",object.chp); } else { printf("%sn",object.chp); } return; } return; }//print()函数:第二个参数如果是1--输出会换行,如果是0--输出不会换行 void setzero(int a[]) { for(int i=0;i<13;i++) { a[i]=0; } return; } void printArrays(int a[]) { printf("Arrays:"); for(int i=0;i<13;i++) { printf("%d",a[i]); } puts(""); return; } int main() { Object ob; { ob.a=0; setzero(ob.sym); ob.sym[2]=1;//此时,ob是"int" print(ob,1); }//给ob复值int类型,调用print()函数打印 { ob.ch='P'; setzero(ob.sym); ob.sym[0]=1;//此时,ob是"char" print(ob,0); }//给ob复值char类型,调用print()函数打印 { strcpy(ob.s,"hello world"); setzero(ob.sym); ob.sym[8]=1;//此时,ob是"String" print(ob,0); }//给ob复值String类型,调用print()函数打印(第一种) { ob.c=66666.6f; setzero(ob.sym); ob.sym[6]=1;//此时,ob是"float" print(ob,1); }//给ob复值float类型,调用print()函数打印 { ob.d=956.25; setzero(ob.sym); ob.sym[7]=1;//此时,ob是"double" print(ob,1); }//给ob复值double类型,调用print()函数打印 { ob.chp="myString"; setzero(ob.sym); ob.sym[12]=1;//此时,ob是"String" print(ob,1); }//给ob复值String类型,调用print()函数打印(第二种) { ob.bol=0; setzero(ob.sym); ob.sym[3]=1;//此时,ob是"bool" print(ob,0); ob.bol=1; setzero(ob.sym); ob.sym[3]=1;//此时,ob是"bool" print(ob,0); }//给ob复值bool类型,调用print()函数打印(第二种) return 0; }
运行结果示例
------------------------------------------------------第五次发项目类文章有点激动啊!-----------------------------------------------------
-----------------------------------------------------【C语言—微项目—自编练习】------------------------------------------------------
----------------------------------------------------------------【TDTX】-----------------------------------------------------------------



