C各种类型变量所占字节

来源:互联网 发布:手机淘宝与支付宝绑定 编辑:程序博客网 时间:2024/05/15 10:43

首先说我的电脑 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

0 0
原创粉丝点击