The problem is that it works perfectly fine in func() function, but in main() the func() returns pointer to pointer to char, and it is accessing illegal memory location and prints the value of that memory location. Why the illegal memory location is accessed in main() function? Please help.
Thanks in advance
MSS
I think the problem is with the local array of 3 char pointers a[3]. That array is out of scope in main().
Try dynamically allocating it in func(), or make it global as suggested by btucho.
The pointer returned by func() points to this array.
Thanks for the reply.If I have the global variable it can be accessed by all functions in the file, so I prefer to declare it as local variable.
One last question:
Is it of NO-USE having a function returning a char pointer, and when to declare one?
Thanks in advance
MSS
You may prefer it to have it local, but it won't work. Make it global as suggested, or better yet, pass the array as parameter to the function, along with the size of the array. That way you are safe (and you can forget about returning anything from the function; it won't be necessary anymore).