about Pointers in C

2019-07-23 21:59发布

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

According to me, value returned by both sizeof() functions should be 4 because a far pointer has 4 byte address.

but the answer in solution manual is 4,2. Can any one explain ?? can anyone plz explain>???

1条回答
唯我独甜
2楼-- · 2019-07-23 22:47

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.

Hence s2 is not a "far" pointer, and is handled as a "near" pointer, which is 16 bits wide in your target.

查看更多
登录 后发表回答