C语言 第二十五节 typedef类型别名

//一,typedef作用简介
1,typedef关键字为各种数据类型定义一个新名字
#include <stdio.h>

typedef int Integer;//给int改名为 Integer 
typedef unsigned int UInterger;//给unsigned改名为UInterger 

typedef float Float;//给float改名为Float 

int main(int argc,const char * argv[]){
	Integer i = -10;//别名定义变量 
	UInterger ui = 11;//与原来的基本类型 
	Float f = 12.39f;//一样。 
	
	printf("%d %d %.2f",i,ui,f);
	
	return 0;
} 
在第3、第4、第6行
分别给int、unsigned int、float起了个别名,
然后在main函数中使用别名定义变量,
用来跟原来的基本类型是完全一样的。

#给类型起别名后,原来的基本类型依旧可用
#别名可以再起一个别名 

//二,typedef与指针
1,typedef 可以给基本数据起别名,
也可以给指针起别名

	#include <stdio.h>
	typedef char *String;//给指针型char *起名String 
	
	int main(int argc,const char *argv[]) {
		//相当于char *str = "this is a string!" ;
		String str = "this is a string!";//用String定义一个字符串 
		
		printf("%s",str);
		
		return 0;
	}

//三,t

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值