不应该在Turbo一个int指针C是大小为4个字节? [英] Shouldn't an int pointer in Turbo C be of size 4 bytes?

查看:143
本文介绍了不应该在Turbo一个int指针C是大小为4个字节?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在涡轮C编译器,一个int指针的大小被示为2个字节当使用的sizeof()算子。现在,如果我打印一个int变量的地址,它出来是8位的十六进制数,这使得地址的大小为32位(或4字节)。

In the Turbo C compiler, the size of an int pointer is shown as 2 bytes when sizeof() operator is used. Now, if I print the address of an int variable, it comes out to be a hexadecimal number of 8 digits, which makes the size of address to be 32 bits (or 4 bytes).

那么,为什么是显示指针的2字节大小的涡轮编译器?

So, why is the Turbo compiler showing 2 bytes size for the pointer?

推荐答案

您的程序小内存模型下编译的,这意味着你的整个数据空间占用不超过64K的空间更多。当程序启动时,DS寄存器指向的数据空间,所以指针只需要16位数据空间引用任何位置。

Your program is compiled under the small memory model, meaning that your entire data space takes up no more than 64K of space. When the program starts, the DS register is pointed at that data space, so pointers only need to be 16 bits to reference any location in the data space.

在中型和大型内存模型,数据空间可能会大于64K,你会发现你的三分球是32位。

In the medium and large memory models, the data space could be larger than 64K, and you'd find your pointers to be 32 bits.

请参阅阿洛克的评论。请参见 GCC 进行更换。

Please see Alok's comments. See gcc for a replacement.

这篇关于不应该在Turbo一个int指针C是大小为4个字节?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆