@yogeesh :
here is the reason why you are getting ch[0] = -1...bcozz
in your code.
#include <stdio.h>

 int main()
 {
         union s
        {
             int i;
             char ch[2];  // this is signed
        };
}

char ch[2] is declared as signed one....so when compiler see that ch[]
is declared as signed and it has all 1's entry ...so it interpret it
as -1.
now execute this code by making ch[] as unsigned .... unsigned char[2];
you will get ch[0] as 255.

so in little endian machine.... ch[0] will be -1 or 255 (depending if
ch[] is signed or unsigned). or if ch[0] = 0 ..then it is big Endian
machine.


On 6/7/12, s yogeesh <[email protected]> wrote:
> Same endian concepts comes into picture but some 1 explain why obj.ch[0] =
> -1 not 255 ??
>
> Code -
>
> #include <stdio.h>
>
> int main()
> {
>         union s
>        {
>             int i;
>             char ch[2];
>        };
>
>
> union s obj;
> obj.i=255;
> printf("%d %d %d\n",obj.i,obj.ch[0],obj.ch[1]);
>
> }
>
> --
> You received this message because you are subscribed to the Google Groups
> "Algorithm Geeks" group.
> To post to this group, send email to [email protected].
> To unsubscribe from this group, send email to
> [email protected].
> For more options, visit this group at
> http://groups.google.com/group/algogeeks?hl=en.
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Algorithm Geeks" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.

Reply via email to