有关指针用C [英] about Pointers in C
问题描述
我开始阅读关于C指针几篇文章和我有一个例子,我不明白。
应该是什么以下code的输出??
I started to read a few articles about pointers in C and I've got one example that I don't understand. What should be the output of following code..??
main()
{
char far *s1 ,*s2;
printf("%d,%d",sizeof(s1),sizeof(s2));
}
OUTPUT-4,2
OUTPUT-4,2
据我来说,双方的sizeof返回的值()函数应该是4,因为一个远指针有4个字节的地址。
According to me, value returned by both sizeof() functions should be 4 because a far pointer has 4 byte address.
但解决方案手册中的答案是4,2。任何一个可以解释?
任何人都可以解释PLZ> ???
but the answer in solution manual is 4,2. Can any one explain ?? can anyone plz explain>???
推荐答案
这是一样的书写
char far *s1;
char *s2;
the "far" is not distributed across all variables, e.g.
char far *s1, ch;
据使得在一个普通的字符ch没有意义的。
far makes no sense on a normal character ch.
因此S2不是远的指针,并且作为接近指针,这是16位宽在您的目标进行处理。
Hence s2 is not a "far" pointer, and is handled as a "near" pointer, which is 16 bits wide in your target.
这篇关于有关指针用C的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!