typedef使用(c语言)

172 阅读1分钟
#include<stdlib.h>
#include<stdio.h>
#include<string.h>


//用途1:给数据类型起别名
//语法:typedef 原名 别名
typedef int MYINT;

void test1() {
	int num1 = 10;
	MYINT num2 = 20;

	printf("num1 = %d\nnum2 = %d\n", num1, num2);
}

//用途2:typedef可以简化struct关键字的使用
typedef struct itcastCPPStudent
{
	char name[64];
	int age;
}student;

//给结构体起别名
//typedef struct itcastCPPStudent student;

void test2() {
	//原来创建对象
	struct itcastCPPStudent s1 = { "张三", 15 };

	//
	student s2 = { "李二", 18 };
}

int main() {

	test1();
	system("pause");
	return 0;
}