Question: main() { char str[] = "hai friends"; char *p,*p1; p = str; p1=p; while(*p != 's') { ++*p++;
} printf(" %s",p1); } http://codepad.org/24hmvzP5 Ans: ibj!gsjfoes On Thu, Jun 16, 2011 at 9:24 AM, sunny agrawal <sunny816.i...@gmail.com>wrote: > @Arpit > Thanks to Bruce Eckel :D > > > On Thu, Jun 16, 2011 at 9:00 PM, Arpit Sood <soodfi...@gmail.com> wrote: > >> @sunny thanks, that post did clear the confusion. >> >> >> On Thu, Jun 16, 2011 at 8:17 PM, Navneet Gupta <navneetn...@gmail.com>wrote: >> >>> Then i would suggest you give the original reference in such cases for >>> still better understanding :) >>> Be it a book or a website. >>> >>> >>> On Thu, Jun 16, 2011 at 8:13 PM, sunny agrawal >>> <sunny816.i...@gmail.com>wrote: >>> >>>> yes copy pasting the exact thing :) >>>> for better understanding :) >>>> >>>> On Thu, Jun 16, 2011 at 8:06 PM, Navneet Gupta >>>> <navneetn...@gmail.com>wrote: >>>> >>>>> @Sunny, it is good that you follow Bruce Eckel, but copy pasting the >>>>> exact thing? :) >>>>> >>>>> >>>>> On Thu, Jun 16, 2011 at 7:34 PM, keyan karthi < >>>>> keyankarthi1...@gmail.com> wrote: >>>>> >>>>>> "hi friends" is a string literal.. ie the string "hi friends" is >>>>>> stored somewhere and a pointer to its base address is returned to >>>>>> pointer p >>>>>> at the time of initialization... u can always make use of this pointer to >>>>>> traverse / access the "literal" but u cant "alter tat" in the code, u r >>>>>> trying to do a "++" operation, which throws a seg fault.... >>>>>> >>>>>> >>>>>> On Thu, Jun 16, 2011 at 2:16 PM, Kamakshii Aggarwal < >>>>>> kamakshi...@gmail.com> wrote: >>>>>> >>>>>>> i still din't get the solution..please explain.. >>>>>>> >>>>>>> On 6/16/11, LALIT SHARMA <lks.ru...@gmail.com> wrote: >>>>>>> > ++*p++ >>>>>>> > ==> >>>>>>> > ++(*p++) , >>>>>>> > increments the value stored at p , and also increments p . >>>>>>> > >>>>>>> > >>>>>>> > >>>>>>> > On Thu, Jun 16, 2011 at 1:10 PM, sunny agrawal >>>>>>> > <sunny816.i...@gmail.com>wrote: >>>>>>> > >>>>>>> >> The place where strict constness is not enforced is with character >>>>>>> >> array literals. You can say >>>>>>> >> char* cp = "howdy"; >>>>>>> >> and the compiler will accept it without complaint. This is >>>>>>> >> technically an error because a character array literal (“howdy” in >>>>>>> >> this case) is created by the compiler as a constant character >>>>>>> array, >>>>>>> >> and the result of the quoted character array is its starting >>>>>>> address in >>>>>>> >> memory. Modifying any of the characters in the array is a runtime >>>>>>> >> error, although not all compilers enforce this correctly. >>>>>>> >> So character array literals are actually constant character >>>>>>> arrays. Of >>>>>>> >> course, the compiler lets you get away with treating them as >>>>>>> nonconst >>>>>>> >> because there’s so much existing C code that relies on this. >>>>>>> >> However, if you try to change the values in a character array >>>>>>> literal, >>>>>>> >> the behavior is undefined, although it will probably work on many >>>>>>> >> machines. >>>>>>> >> If you want to be able to modify the string, put it in an array: >>>>>>> >> char cp[] = "howdy"; >>>>>>> >> Since compilers often don’t enforce the difference you won’t be >>>>>>> >> reminded to use this latter form and so the point becomes rather >>>>>>> >> subtle. >>>>>>> >> >>>>>>> >> >>>>>>> >> On Thu, Jun 16, 2011 at 12:59 PM, amit kumar >>>>>>> >> <amitthecoo...@gmail.com>wrote: >>>>>>> >> >>>>>>> >>> //kk >>>>>>> >>> //In place of >>>>>>> >>> >>>>>>> >>> char *p="hai friends",*p1; >>>>>>> >>> if i declare as >>>>>>> >>> char p[]="hai friends"; >>>>>>> >>> char *p1; >>>>>>> >>> //then ?? >>>>>>> >>> >>>>>>> >>> >>>>>>> >>> On Thu, Jun 16, 2011 at 8:16 AM, DIPANKAR DUTTA < >>>>>>> >>> dutta.dipanka...@gmail.com> wrote: >>>>>>> >>> >>>>>>> >>>> It's ok.. >>>>>>> >>>> >>>>>>> >>>> char *p="hai friends"...not correct.... >>>>>>> >>>> >>>>>>> >>>> bcz you did allocate memory for that string but assiging poiter >>>>>>> to the >>>>>>> >>>> base address.. from where gcc will get the bse address of that >>>>>>> string >>>>>>> >>>> when u >>>>>>> >>>> r not actually allocate memory for it? thus it generate SIGSEG >>>>>>> signal >>>>>>> >>>> and >>>>>>> >>>> give invalid memory address...ie. segmentation fault >>>>>>> >>>> use malloc or use >>>>>>> >>>> char p[]=".."; >>>>>>> >>>> >>>>>>> >>>> >>>>>>> >>>> >>>>>>> >>>> >>>>>>> >>>> >>>>>>> >>>> >>>>>>> >>>> On Thu, Jun 16, 2011 at 4:49 AM, DK <divyekap...@gmail.com> >>>>>>> wrote: >>>>>>> >>>> >>>>>>> >>>>> Gives me a SEGFAULT on gcc. >>>>>>> >>>>> Probably due to undefined behaviour. >>>>>>> >>>>> >>>>>>> >>>>> -- >>>>>>> >>>>> DK >>>>>>> >>>>> >>>>>>> >>>>> http://twitter.com/divyekapoor >>>>>>> >>>>> http://www.divye.in >>>>>>> >>>>> >>>>>>> >>>>> -- >>>>>>> >>>>> You received this message because you are subscribed to the >>>>>>> Google >>>>>>> >>>>> Groups "Algorithm Geeks" group. >>>>>>> >>>>> To view this discussion on the web visit >>>>>>> >>>>> https://groups.google.com/d/msg/algogeeks/-/QVAjKMQiWvoJ. >>>>>>> >>>>> >>>>>>> >>>>> 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. >>>>>>> >>>>> >>>>>>> >>>> >>>>>>> >>>> >>>>>>> >>>> >>>>>>> >>>> -- >>>>>>> >>>> Thanks and Regards, >>>>>>> >>>> ------------------------------ >>>>>>> >>>> *DIPANKAR DUTTA* >>>>>>> >>>> Visiting Research Scholar >>>>>>> >>>> Dept of Computing, >>>>>>> >>>> Macquarie University, Sydney, Australia >>>>>>> >>>> ph.no-+61 2 98509079 ( Mon-Fri 10:15-7:00) Sydney time >>>>>>> >>>> email: dipankar.du...@mq.edu.au >>>>>>> >>>> >>>>>>> >>>> >>>>>>> >>>> >>>>>>> >>>> -- >>>>>>> >>>> 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. >>>>>>> >>> >>>>>>> >> >>>>>>> >> >>>>>>> >> >>>>>>> >> -- >>>>>>> >> Sunny Aggrawal >>>>>>> >> B-Tech IV year,CSI >>>>>>> >> Indian Institute Of Technology,Roorkee >>>>>>> >> >>>>>>> >> >>>>>>> >> -- >>>>>>> >> 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. >>>>>>> >> >>>>>>> > >>>>>>> > >>>>>>> > >>>>>>> > -- >>>>>>> > Lalit Kishore Sharma, >>>>>>> > >>>>>>> > IIIT Allahabad (Amethi Capmus), >>>>>>> > 6th Sem. >>>>>>> > >>>>>>> > -- >>>>>>> > 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. >>>>>>> > >>>>>>> > >>>>>>> >>>>>>> >>>>>>> -- >>>>>>> Regards, >>>>>>> Kamakshi >>>>>>> kamakshi...@gmail.com >>>>>>> >>>>>>> -- >>>>>>> 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. >>>>>> >>>>> >>>>> >>>>> >>>>> -- >>>>> --Navneet >>>>> >>>>> -- >>>>> 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. >>>>> >>>> >>>> >>>> >>>> -- >>>> Sunny Aggrawal >>>> B-Tech IV year,CSI >>>> Indian Institute Of Technology,Roorkee >>>> >>>> -- >>>> 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. >>>> >>> >>> >>> >>> -- >>> --Navneet >>> >>> -- >>> 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. >>> >> >> >> >> -- >> Regards, >> Arpit Sood >> >> -- >> 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. >> > > > > -- > Sunny Aggrawal > B-Tech IV year,CSI > Indian Institute Of Technology,Roorkee > > -- > 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.