C语言查看各种数据类型的sizeintptr_t 定义在/usr/include/stdint.h,#if __WORDSIZE == 64# ifndef __intptr_t_defined typedef long int intptr_t; # define __intptr_t_defined # endif typedef unsigned long int uintptr_t; #else # ifndef __intptr_t_defined typedef int intptr_t; # define __intptr_t_defined # endif typedef unsigned int uintptr_t; #endif #include <stdio.h>#include <stdint.h>int main(void) { int *ptr; printf("sizeof int is %d
",sizeof(int)); printf("sizeof char is %d
",sizeof(char)); printf("sizeof short is %d
",sizeof(short)); printf("sizeof long is %d
",sizeof(long)); printf("sizeof float is %d
",sizeof(float)); printf("sizeof double is %d
",sizeof(double)); printf("sizeof pointer is %d
",sizeof(ptr)); printf("sizeof unsiged int is %d
",sizeof(unsigned int)); //store pointers in integer type,use size_t,INT_PTR,intptr_t; printf("sizeof size_t is %d
",sizeof(size_t)); //intptr_t defines in stdint.h printf("sizeof intptr_t is %d
",sizeof(intptr_t)); //INT_PTR only exist in windows //printf("sizeof INT_PTR is %d
",sizeof(INT_PTR));
}查看各种数据类型的MAX 和MIN 值#include <stdio.h>#include <limits.h> #include <float.h> int main() { printf("The value of INT_MAX is %i
", INT_MAX); printf("The value of INT_MIN is %i
", INT_MIN); printf("An int takes %d bytes
", sizeof(int));printf("The value of FLT_MAX is %f
", FLT_MAX); printf("The value of FLT_MIN is %.50f
", FLT_MIN); printf("A float takes %d bytes
", sizeof(float));printf("The value of CHAR_MAX is %d
", CHAR_MAX); printf("The value of CHAR_MIN is %d
", CHAR_MIN); printf("A CHAR takes %d bytes
", sizeof(char));printf("The value of DBL_MAX is %f
", DBL_MAX); printf("The value of DBL_MIN is %.50f
", DBL_MIN); printf("A double takes %d bytes
", sizeof(double));printf("The value of SHRT_MAX is %d
", SHRT_MAX); printf("The value of SHRT_MIN is %d
", SHRT_MIN); printf("A short takes %d bytes
", sizeof(short));printf("The value of LONG_MAX is %Ld
", LONG_MAX); printf("The value of LONG_MIN is %Ld
", LONG_MIN); printf("A long takes %d bytes
", sizeof(long)); return 0; }在stdint.h 里面定义了很多int*_t 和uint*_t 类型。#include <apue.h>#include <stdint.h> #include <limits.h>int main(int argc, char *argv[]) { printf("CHAR_BIT is %d
",CHAR_BIT); printf("sizeof(char) is %d
",sizeof(char)); printf("sizeof(short) is %d
",sizeof(short)); printf("sizeof(int) is %d
",sizeof(int)); printf("sizeof(long) is %d
",sizeof(long)); printf("sizeof(long long) is %d
",sizeof(long long));
printf("sizeof(int8_t) is %d
",sizeof(int8_t)); printf("sizeof(int16_t) is %d
",sizeof(int16_t)); printf("sizeof(int32_t) is %d
",sizeof(int32_t)); printf("sizeof(int64_t) is %d
",sizeof(int64_t)); printf("sizeof(uint8_t) is %d
",sizeof(uint8_t)); printf("sizeof(uint16_t) is %d
",sizeof(uint16_t)); printf("sizeof(uint32_t) is %d
",sizeof(uint32_t)); printf("sizeof(uint64_t) is %d
",sizeof(uint64_t));
char a,b; printf("sizeof(a+b) is %d
",sizeof(a+b)); }本文永久更新链接地址:http://www.linuxidc.com/Linux/2015-12/126197.htm