my question is that if i put return statement at the end in comments the program goes into a runtime error,y is it so?is the return statement neccessary coz in other functions returning integer or float it is not neccessary to return them.
You should always return value from value returning functions. You just got lucky with your previous attempts and compiler decided to return primitive types through CPU registers. When you are trying to return a string it uses stack instead and as function does not place anything on it, it lead to stack corruption and crash.
TL;DR: failing to return a value from non-void function is undefined behavior and should be always avoided