简体   繁体   中英

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. 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>???

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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