码迷,mamicode.com
首页 > 其他好文 > 详细

01_基本数据类型

时间:2018-10-23 21:05:51      阅读:322      评论:0      收藏:0      [点我收藏+]

标签:byte   tom   star   定义   return   基本数据类型   lin   tar   理解   

基本数据类型

1、什么是数据类型?

数据类型可以理解为固定内存大小的别名
数据类型是创建变量的模子
技术分享图片

2、什么是变量

变量是一段(具体)连续存储空间的别名
程序通过变量申请并命名存储空间
通过变量名可以使用存储空间
技术分享图片

3、代码练习

(1)类型与变量的关系

#include <stdio.h>

int main()
{
    char c = 0;
    short s = 0;
    int i = 0;

    printf("sizeof(char) = %d, sizeof(c) = %d\n", sizeof(char), sizeof(c));
    printf("sizeof(short) = %d, sizeof(s) = %d\n", sizeof(short), sizeof(s));
    printf("sizeof(int) = %d, sizeof(i) = %d\n", sizeof(int), sizeof(i));

    return 0;
}

输出结果为:
技术分享图片
(2)自定义类型与创建变量

#include <stdio.h>

typedef int INT32;
typedef unsigned char BYTE;
typedef struct _tag_ts
{
    BYTE b1;
    BYTE b2;
    short s;
    INT32 i;
} TS;

int main()
{
    INT32 i32;
    BYTE b;
    TS ts;

    printf("%d, %d\n", sizeof(INT32), sizeof(i32));
    printf("%d, %d\n", sizeof(BYTE), sizeof(b));
    printf("%d, %d\n", sizeof(TS), sizeof(ts));

    return 0;
}

输出结果为:
技术分享图片

4、小结

技术分享图片

<wiz_tmp_tag id="wiz-table-range-border" contenteditable="false" style="display: none;">





01_基本数据类型

标签:byte   tom   star   定义   return   基本数据类型   lin   tar   理解   

原文地址:https://www.cnblogs.com/chen-ace/p/9838161.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!