char short 类型的提升

来源:互联网 发布:北京大学远程网络教育 编辑:程序博客网 时间:2024/06/05 00:11
// char和short的类型提升.cpp : Defines the entry point for the console application.
//


#include "stdafx.h"
#include <stdio.h>


int main(int argc, char* argv[])
{



printf("%d\n",sizeof('A'));//VC6中一个字符也就是一个字节


printf("%d\n",sizeof("AB"));//一个字符串包含有个'\0'是3个字节
printf("%d\n",sizeof("韩凯浩"));//字符串包含有个'\0'一个中文是2个字共7个字节


//char 和 short进行运算都会进行类型的提升成为int类型或者unsigned int类型


char cha='A';
char chb='B';
printf("%d\n",sizeof(cha));


printf("char类型提升%d\n",sizeof(cha+chb));// 两个char类型共2字节相加就提示为int的4个字节
printf("char类型提升%d\n",sizeof(cha/chb));




short sha=155;
short shb=144;
printf("short=%d\n",sha);
printf("short类型的提升=%d\n",sizeof(sha+shb));




return 0;
}
0 0
原创粉丝点击