基本数据类型

来源:互联网 发布:库里2016季后赛数据 编辑:程序博客网 时间:2024/04/29 03:22

C语言中最基本的应该就是数据类型,下面给大家介绍一下基本数据类型

#include <stdio.h>#include <stdlib.h>void main(){    int a = 0;    float b = 0;    double c = 0;    char d = 0;    long int e = 0;    long double g = 0;    long float h = 0;/*这样写不是太合适,会有warning*/    printf("int a = %d\n",sizeof(a));    printf("float b = %d\n",sizeof(b));    printf("double c = %d\n",sizeof(c));    printf("char d = %d\n",sizeof(d));    printf("long int e = %d\n",sizeof(e));    printf("long double g = %d\n",sizeof(g));    printf("long float h = %d\n",sizeof(h));    char hello[] = {'H', 'e','l','l','o'};    printf("hello = %d\n",sizeof(hello));    char world[] = "world";    printf("world = %d\n",sizeof(world));    int *i = NULL;    double *j = NULL;    float *k = NULL;    char *l = NULL;    printf("指针其实都是%d,%d,%d,%d",sizeof(i),sizeof(j),sizeof(k),sizeof(l));}

运行结果:
这里写图片描述
很容易看出来这些基本数据类型所占的空间大小,其中要注意一下,在字符数组与字符串的区别,很容易看出他们之间是隔了一,因为字符串的后面会自动加一个’/0’,这是系统自己加上去的。还有就是要注意这里的5不是五个字符,而是char类型是1,然后1 * 5 = 5;如果是int[5]那么就是 20 = 4 * 5。所有的指针都是4,就这样吧,还有什么不全之处欢迎大家指出来,因为我也是一名小白,只是在记录自己的学习过程。

0 0