@programming love:I can understand what u say but my doubt is that for the first output which is 2, according to your example, p has address 10 which it points to.And as u say int * tends to dereference 2 bytes so that wud be now 10 and 11.finally char * takes only 1 byte so why is value at 11 address printed( i mean 02) and not value at 10 address( 00)
similarly for the second output where u say p+1 goes from 10 to 11 due to char type.when u do int* u say it dereferences 11 and 12. so then when char * is done finally why does it print the one at 12 and not 11? please correct my understanding if wrong On Mon, Aug 15, 2011 at 10:44 AM, programming love < love.for.programm...@gmail.com> wrote: > The internal representation of array is this: > > suppose that the address starts from decimal number 10 and integer occupies > 2 bytes > > 10- 0002 ( num 2 in hex) > 12- 0003 ( num 3 in hex) > 14- 0004 ( num 4 in hex) > > Now p points to address 10 and is type char. (Even after type casts) p+1 > will increment address by 1 byte (since it's char). p will now point to 11 > (int *) will say that when de-referenced 2 bytes should be extracted. So the > 2 bytes extracted are 11, 12. Numbers in these bytes are 02 and 00 > > 10- 00*02* ( num 2 in hex) > 12- *00*03 ( num 3 in hex) > 14- 0004 ( num 4 in hex) > > now (char *) says extract 1 byte for me. The extracted byte is 00. Hence 0 > is printed > > *Correct me if i am wrong.* > > > -- > You received this message because you are subscribed to the Google Groups > "Algorithm Geeks" group. > To post to this group, send email to algogeeks@googlegroups.com. > To unsubscribe from this group, send email to > algogeeks+unsubscr...@googlegroups.com. > For more options, visit this group at > http://groups.google.com/group/algogeeks?hl=en. > -- "People often say that motivation doesn't last. Well, neither does bathing - that's why we recommend it daily." -- You received this message because you are subscribed to the Google Groups "Algorithm Geeks" group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.