DD24
DD24

Reputation: 61

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

Upvotes: 1

Views: 967

Answers (1)

franji1
franji1

Reputation: 3156

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.

Upvotes: 6

Related Questions