您的位置:首页 > 编程语言 > C语言/C++

C各种类型变量所占字节

2016-04-08 12:29 417 查看
首先说我的电脑 win7 64 位

编译器gcc 5.2.0 (32位64为兼容的)

#include <stdio.h>
#include <stdlib.h>

int main(int argc, char const *argv[])
{
printf("the byte of          char is %d\n", sizeof(char));
printf("the byte of signed   char is %d\n", sizeof(signed char));
printf("the byte of unsigned char is %d\n", sizeof(unsigned char));

printf("///////////////////////////////////////////////////\n");
printf("the byte of          int is %d\n", sizeof(int));
printf("the byte of signed   int is %d\n", sizeof(signed int));
printf("the byte of unsigned int is %d\n", sizeof(unsigned int));

printf("///////////////////////////////////////////////////\n");
printf("the byte of short is %d\n", sizeof(short));
printf("the byte of long is %d\n", sizeof(long));
printf("the byte of signed short   int is %d\n", sizeof(signed short int));
printf("the byte of unsigned short int is %d\n", sizeof(unsigned short int));
printf("the byte of signed long    int is %d\n", sizeof(signed long int));
printf("the byte of unsigned long  int is %d\n", sizeof(unsigned long int));
printf("the byte of signed long long    int is %d\n", sizeof(signed long long int));
printf("the byte of unsigned long long  int is %d\n", sizeof(unsigned long long int));

printf("///////////////////////////////////////////////////\n");
printf("the byte of float is %d\n", sizeof(float));
printf("the byte of double is %d\n", sizeof(double));
printf("///////////////////////////////////////////////////\n");
printf("the byte of int * is %d\n", sizeof(int *));
printf("the byte of char* is %d\n", sizeof(char*));
printf("the byte of float* is %d\n", sizeof(float*));
printf("the byte of double* is %d\n", sizeof(double*));
return 0;
}


运行结果



我的各数据类型占字节数

char 1

int 4

float 4

double 8

short 2

long 4

long long 8

指针是 8
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  c语言 数据类型