C中指针的大小是否有所不同? [英] Does the size of pointers vary in C?

查看:24
本文介绍了C中指针的大小是否有所不同?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

可能的重复:
指针的大小可以根据什么而变化吗?s 指向?
是否有任何平台指向不同类型的指针有不同的大小?

c 中指向浮点数的指针的大小与指向 int 的指针的大小是否可能不同?尝试过之后,我对各种指针都得到了相同的结果.

Is it possible that the size of a pointer to a float in c differs from a pointer to int? Having tried it out, I get the same result for all kinds of pointers.

#include <stdio.h>
#include <stdlib.h>

int main()
{
    printf("sizeof(int*): %i
", sizeof(int*));
    printf("sizeof(float*): %i
", sizeof(float*));
    printf("sizeof(void*): %i
", sizeof(void*));
    return 0;
}

这里的输出(OSX 10.6 64 位)

Which outputs here (OSX 10.6 64bit)

sizeof(int*): 8
sizeof(float*): 8
sizeof(void*): 8

我可以假设不同类型的指针具有相同的大小吗(当然在一个拱形上)?

Can I assume that pointers of different types have the same size (on one arch of course)?

推荐答案

指针在同一个拱形上的大小并不总是相同.

Pointers are not always the same size on the same arch.

您可以阅读更多关于近"、远"和大"指针的概念,仅作为指针大小不同的示例...

You can read more on the concept of "near", "far" and "huge" pointers, just as an example of a case where pointer sizes differ...

http://en.wikipedia.org/wiki/Intel_Memory_Model#Pointer_sizes

这篇关于C中指针的大小是否有所不同?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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