Is the pointer returned by strdup( ) points to heap memory ? Man page says: The strdup() function allocates memory and copies into it the string addressed by s1, including the terminating null character. Regards and thanks, Vishant
strdup() uses malloc to allocate so pointer returned should point to heap.
Also you should free it.
#include
Were it stack based, you would get some kind of error accessing
that chunk of memory after the function that caused that stack
frame went away at some point, like when the stack regrew past
that point, and overwrote your string. Not right away, every time,
mind you, but eventually somewhere.
So, I think it save to assume it is heap memory.
vishaantsingh via cpp-l