Jump to content
ChetanaSforum

Recommended Posts

char *someFun1() { char temp[ ] = “string"; return temp; } char *someFun2() { char temp[ ] = {‘s’, ‘t’,’r’,’i’,’n’,’g’}; return temp; } int main() { puts(someFun1()); puts(someFun2()); }

Share this post


Link to post
Share on other sites

you shouldn't do this. As you are passing the address of local variable it will may give segmentation error or garbage value....

what is the difference between the current return statement and passing values to a functionby reference ? both will still pass the local variable's memory address isn't it ?

Share this post


Link to post
Share on other sites

what is the difference between the current return statement and passing values to a functionby reference ? both will still pass the local variable's memory address isn't it ?

output will b string in both caseu r passing address from both functions which can b accessed outside function..but that temp variable has no scope outside the function..

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now



×