i=300 // binary = 00000001 00101100 // in case of little Endien it will be saved like this :- 00000001 00101100 //suppose int = 2 bytes and char = 1 byte char *ptr = &i; // take care it *char *ptr* not *int* **ptr*....so what will happen
*ptr will be pointing to 00101100 *++ptr // now ptr is pointing to 00000001 bcozz it is a char * hence it will be increment by 1 byte ptr=2 // now 00000001 will be converted to 00000010 so final value of i becomes 0000001000101100 = 556 now you can try for big endian .... On Thu, Jun 7, 2012 at 12:27 AM, g4ur4v <gauravyadav1...@gmail.com> wrote: > > > main() > { > int i=300; > char *ptr = &i; > *++ptr=2; > printf("%d",i); > } > > -- > 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. > > -- 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.