简体   繁体   English

关于C中的指针

[英]about Pointers in C

I started to read a few articles about pointers in C and I've got one example that I don't understand. 我开始阅读一些有关C语言中指针的文章,并且有一个我不理解的示例。 What should be the output of following code..?? 以下代码的输出应该是什么?

    main()
     {
      char far *s1 ,*s2;
      printf("%d,%d",sizeof(s1),sizeof(s2));
     }

OUTPUT-4,2 输出-4,2

According to me, value returned by both sizeof() functions should be 4 because a far pointer has 4 byte address. 据我说,两个sizeof()函数返回的值应该为4,因为far指针的地址为4字节。

but the answer in solution manual is 4,2. 但是解决方案手册中的答案是4,2。 Can any one explain ?? 谁能解释一下? can anyone plz explain>??? 任何人都可以解释> ???

It's the same as writing 和写作一样

char far *s1;
char *s2;
the "far" is not distributed across all variables, e.g.
char far *s1, ch;

far makes no sense on a normal character ch. 普通字符ch远远没有意义。

Hence s2 is not a "far" pointer, and is handled as a "near" pointer, which is 16 bits wide in your target. 因此,s2不是“远”指针,而是作为“近”指针处理的,它在目标中为16位宽。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM