CºÍC++ÖеÄÖ÷ÒªÊý¾ÝÀàÐͺÍ×Ö½Ú´óС(
C/C++µÄд·¨ÊDz»¿ÆѧºÍ²»ÑϽ÷µÄ¡£ÒòΪCºÍC++ËäÈ»ÓïÒ壬µ«ÊÇÉè¼Æ˼ÏëÊǽṹ»¯ÓëÃæÏò¶ÔÏó. C±ê×¼¹æ·¶ÓëC++µÄ±ê×¼¹æ·¶Ò²ÊÇÁ½¸öÎı¾¡£½üÀ´×ÐϸÑо¿ÁËËüÃǵÄÊý¾ÝÀàÐÍ£¬²ÅÖªµÀÆäÀ´ÁúÈ¥Âö£¬ÕæÕý×öµ½ÆäʵËùÒÔÈ»¡£
1¡¢CÓïÑÔ¶¨ÒåÁË5ÖÖ»ù±¾Êý¾ÝÀàÐÍ
char(×Ö·û), int(ÕûÊý), float(µ¥¾«¶È), double(Ë«¾«¶È),void;
ÔÚ32λ»úÆ÷ÉÏ,sizeofµÄÆäÖµ·Ö±ðΪ£º
sizeof(char)=1, sizeof(int)=4, sizeof(float)=4, sizeof(double)=8;
sizeof(char*)=4;(ÈκÎÀàÐÍÖ¸Õë±äÁ¿Îª32λ¼´4¸ö×Ö½Ú)
2¡¢C++ÓïÑÔÓÚC»ù´¡ÉÏÔö¼Ó2ÖÖÊý¾ÝÀàÐÍ£º
bool(²¼¶û),wchar_t(¿í×Ö·û);
ÔÚ32λ»úÆ÷ÉÏ,sizeofµÄÆäÖµ·Ö±ðΪ:
sizeof(bool)=1, sizeof(wchar_t)=2, sizeof(bool*)=sizeof(wchar_t*)=4;
3¡¢Êý¾ÝÀàÐ͵Ļù±¾ÐÞÊηû:
signed(ÓзûºÅ), unsigned(ÎÞ·ûºÅ),long(³¤Õû),short(¶ÌÕû)
4¡¢²âÊÔ´úÂë:
size_t nchar=sizeof(char);
size_t nfloat=sizeof(float);
size_t ndouble=sizeof(double);
size_t nint = sizeof(int);
a.Format("CÓïÑÔÊý¾ÝÀàÐͳ¤¶È:char=%d,float=%d,double=%d,int=%d",nchar,nfloat,ndouble,nint);
AfxMessageBox(a);
nint = sizeof(int*);
nchar = sizeof(char*);
ndouble = sizeof(double*);
nfloat = sizeof(float*);
a.Format("CÓïÑÔÖ¸ÕëÀàÐͳ¤¶È:char*=%d,float*=%d,double*=%d,int*=%d",nchar,nfloat,ndouble,nint);
AfxMessageBox(a);
size_t nbool=sizeof(bool);
size_t nwchar=sizeof(wchar_t);
a.Format("C++ÐÂÔöÊý¾ÝÀàÐͳ¤¶È:bool=%d,wchar_t=%d,bool*=%d,wchar_t*=%d",nbool,nwchar,sizeof(bool*),sizeof(wchar_t*));
AfxMessageBox(a);
5.Àí½â´úÂë
//A
²ÉÓÃ32λѰַ·½Ê½£¬ÔòÊý×échar**[4][4]Õ¼ÓÃ×Ö½Ú=4*4*4×Ö½Ú(32bit)=64×Ö½Ú
//B
#include "stdio.h"
int main()
{
int *p;
printf("%d", sizeof(p));
return 0;
}
×î½üһֱæ±ÏÒµµÄÏà¹ØÊÂÇ飬¼ÓÉϹ¤×÷£¬×ªÑۼ䣬ÓÖµ½Ôµ×ÁË£¬Ö®Ç°³ÐŵµÄÿÔÂһƪ²©ÎÄ£¬Ç°¼¸Ìì¾ÍÒ»Ö±ÔÚÑ°ÕÒµ½µ×Ҫдʲô£¬½üÁ½ÌìÓÖͻȻ·¢ÏÖÓкܶණÎ÷¿ÉÒÔд¡£±¾Æª¾ÍÏÈÑÓÐø֮ǰµÄһƪ»ùÓÚCookieµÄ°²È«¼ì²é»úÖÆ£¨ÉîÈëC/C++Ö®»ùÓÚCookieµÄ°²È«¼ì²é£¨VS2005£©£©À´½éÉÜÏÂÁíÍâÒ»ÖÖÔÚDEBUG°æ±¾Ïµİ²È«¼ì²é£¬Ò²¾ÍÊÇCheckStackVars¼ì ......