我也同意songhtao(三十年孤独)的说法,就是把buffer定义成一个类,它的返回值还是4!
sizeof (keyword)
Returns the size, in bytes, of the given expression or type (as type size_t ).
如果是用new分配内存的话,返回的是指针的size,如果是一般的定义,返回的是它的字节数
class abc
{
int a,b, c;
char d;
};
void __fastcall TForm1::Button1Click(TObject *Sender)
{
//abc *hello=new abc;
abc hello;
int i=sizeof(hello);
ShowMessage(IntToStr(i));
}
结果是16