1. ±à³ÌѧϰÍø > ±à³Ì½Ì³Ì > CÓïÑÔ½Ì³Ì > CÓïÑÔʵÀý-¼ÆËã int, float, double ºÍ char ×Ö½Ú´óС

CÓïÑÔʵÀý-¼ÆËã int, float, double ºÍ char ×Ö½Ú´óС

C ÓïÑÔʵÀý

ʹÓà sizeof ²Ù×÷·û¼ÆËãint, float, double ºÍ charËÄÖÖ±äÁ¿×Ö½Ú´óС¡£

sizeof ÊÇ C ÓïÑÔµÄÒ»ÖÖµ¥Ä¿²Ù×÷·û£¬ÈçCÓïÑÔµÄÆäËû²Ù×÷·û++¡¢--µÈ£¬Ëü²¢²»ÊǺ¯Êý¡£

sizeof ²Ù×÷·ûÒÔ×Ö½ÚÐÎʽ¸ø³öÁËÆä²Ù×÷ÊýµÄ´æ´¢´óС¡£

ʵÀý

#include <stdio.h> int main(){ int integerType; float floatType; double doubleType; char charType; // sizeof ²Ù×÷·ûÓÃÓÚ¼ÆËã±äÁ¿µÄ×Ö½Ú´óС printf("Size of int: %ld bytes\n",sizeof(integerType)); printf("Size of float: %ld bytes\n",sizeof(floatType)); printf("Size of double: %ld bytes\n",sizeof(doubleType)); printf("Size of char: %ld byte\n",sizeof(charType)); return 0; }

ÔËÐнá¹û£º

Size of int: 4 bytes
Size of float: 4 bytes
Size of double: 8 bytes
Size of char: 1 byte

¼ÆËã long long, long double ×Ö½Ú´óС

ʵÀý

#include <stdio.h>int main(){ int a; long b; long long c; double e; long double f; printf("Size of int = %ld bytes \n", sizeof(a)); printf("Size of long = %ld bytes\n", sizeof(b)); printf("Size of long long = %ld bytes\n", sizeof(c)); printf("Size of double = %ld bytes\n", sizeof(e)); printf("Size of long double = %ld bytes\n", sizeof(f)); return 0; }

ÔËÐнá¹û£º

Size of int = 4 bytes 
Size of long = 8 bytes
Size of long long = 8 bytes
Size of double = 8 bytes
Size of long double = 16 bytes

±¾ÎÄÓÉIT½ÌѧÍøÕûÀí·¢²¼£¬×ªÔØÇë×¢Ã÷³ö´¦£ºhttp://www.clang.cc//jiaocheng/cyuyan/1115.html

ÁªÏµÎÒÃÇ

ÔÚÏß×Éѯ£ºµã»÷ÕâÀï¸øÎÒ·¢ÏûÏ¢

×Éѯµç»°£º400-998-2681

¹¤×÷ʱ¼ä£º7*24СʱÎÞÐÝ