char * in array of int

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • noob15
    New Member
    • Jun 2010
    • 13

    char * in array of int

    Code:
    	int aa[3]={300,3,4};
    	char *p;
    	p=aa;
    	p=(char*)((int *)(p));
    	printf("%d",*p);
    	p=(int*)(p+1);
    	printf(" %d",*p);
    	p++;
    	printf(" %d",*p);
    output :: 44 1 0

    can someone help me with why this output is coming (especially 1 after 44)
    Last edited by Banfa; Jul 31 '10, 09:04 PM. Reason: Added [code] ... [/code] tags
  • Banfa
    Recognized Expert Expert
    • Feb 2006
    • 9067

    #2
    It is probable that line 4 of you code does nothing.

    As to the values you are getting consider the individual value of the bytes in each integer.

    Comment

    • noob15
      New Member
      • Jun 2010
      • 13

      #3
      Originally posted by Banfa
      It is probable that line 4 of you code does nothing.

      As to the values you are getting consider the individual value of the bytes in each integer.
      means is it like this

      a[0] = 00000000 00000000 00000001 00101100

      since my linux x86 architecture uses little-endian it is stored as 00101100 00000001 00000000 00000000

      means answer will be different in case of Big-endian ??

      Comment

      • Banfa
        Recognized Expert Expert
        • Feb 2006
        • 9067

        #4
        Yes .

        Comment

        Working...