On Thu, 2004-03-04 at 16:07, Arindam Dey wrote: > Try adding these two statements and changing your foo() function > > char * foo() > { > char string[200]; > char * ptr=NULL; > strcpy(string,"hello world"); > printf("StrAddr=%x\n",&string[0]); // Print address of the > starting // of the string > ptr=string; > printf("PtrAddr=%x\n",ptr); //Print the address of the ptr > //not the contents > }
Apologies for replying to my own mail. But I or my MUA made a horrendous formatting error for my comment above. The word "starting" will be after the beginning of the second "//" comment starter. Although I am pretty sure you will correct my ineptitude automatically there was another reason to reply again. You can use the value of the "ptr" in the main function although it is a local variable because it is made on the heap and thus although the pointer itself is gone meaning you cannot use ptr->something in main but since you have not cleared or freed the memory location using delete() in the function the value stored in the memory location is still present and thus the printf statement in the main is happily printing whatever is stored in that particular memory location. Since the variable "string" in main has been assigned the memory location or address earlier being used by the ptr in the function foo. Regards, -- Arindam Dey The mind is not a vessel to be filled but a fire to be kindled. GPG FPR: B8E3 219E F129 F970 F4A7 BC50 9636 504A BEDF 5739 _______________________________________________ ilugd mailinglist -- [EMAIL PROTECTED] http://frodo.hserus.net/mailman/listinfo/ilugd Archives at: http://news.gmane.org/gmane.user-groups.linux.delhi http://www.mail-archive.com/[EMAIL PROTECTED]/