structDemo1
# include <iostream.h> # include <malloc.h> enum EType{ One = 1,Tow,Three }; struct S1{ int id ; char name [111]; long version ; }; int main(void){ EType one = Tow; cout << "one = " << one << endl ; cout << "hello world !! " << endl ; cout << endl << "hello world !! << endl "; for (int i (1) ; i <4 ;i++){ EType type = (EType) i ; if(One == type ) cout << " is One " << endl; if(Tow == type) cout << " is Tow " << endl; if(Three == type) cout << " is Three " << endl; } cout << "i = " << i <<endl; S1 s1 = {1,"s1",11}; cout << " s1.id = " << s1.id << " , s1.name = " << s1.name << " , s1.version = " << s1.version << endl; S1 * ps1 = &s1; cout << "ps1->id = " << ps1->id << endl; ps1 = (struct S1 *)malloc( sizeof(struct S1)); ps1->id = 2; (*ps1).version = 2; cout << " ps1->id = "<< ps1->id << " ,(*ps1).version = " <<(*ps1).version << endl; return 0 ; }
原文:http://www.cnblogs.com/mjorcen/p/3817981.html