0. 理解
1. 基本数据类型
typedef int Integer;
int main() {
Integer num = 100;
printf("%i\n", num);
return 0;
}
2. 指针
typedef char *String;
int main() {
String name = "王小熊";
printf("name = %s\n", name);
return 0;
}
int sum(int v1, int v2) {
return v1 + v2;
}
int minus(int v1, int v2) {
return v1 - v2;
}
typedef int(*functionPotinter)(int , int);
int main() {
functionPotinter sumP = sum;
printf("sum = %i\n", sumP(20, 10));
functionPotinter minusP = minus;
printf("minus = %i\n", minusP(20, 10));
return 0;
}
3. 结构体
struct Person {
char *name;
int age;
double height;
};
typedef struct Person SPerson;
int main() {
SPerson sp = {"秦子阳", 18, 1.88};
printf("%s\n", sp.name);
return 0;
}
typedef struct Person {
char *name;
int age;
double height;
} Sperson;
int main() {
Sperson sp = {"秦子阳", 18, 1.88};
printf("%s\n", sp.name);
return 0;
}
typedef struct {
char *name;
int age;
double height;
} Sperson;
int main() {
Sperson sp = {"秦子阳", 18, 1.88};
printf("%s\n", sp.name);
return 0;
}
4. 枚举
enum Gender {
kGenderMale,
kGenderFemale
};
typedef enum Gender SEX;
int main() {
SEX sex = kGenderFemale;
printf("%i\n", sex);
return 0;
}
typedef enum Gender {
kGenderMale,
kGenderFemale
} SEX;
int main() {
SEX sex = kGenderFemale;
printf("%i\n", sex);
return 0;
}
typedef enum {
kGenderMale,
kGenderFemale
} SEX;
int main() {
SEX sex = kGenderFemale;
printf("%i\n", sex);
return 0;
}
网友评论