Please look at the following code snippets:
char str[]="abcd"; // Gets stored in stack frame.
char *str="abcd"; // Where does this gets stored?
In case of first declaration ie char str[]="abcd"; the string "abcd" gets stored in the stack frame of the invoked funciton. I wonder where does the string gets stored when we declare char *str="abcd"; (Is it in the heap?). Please reply.
Thanks
Iqbal
Recommended Answers
Jump to Post(Is it in the heap?)
I think both goes on the stack both times. Would only go on the heap/free store if you use the 'new' keyword.
Wolfie ?
p.s.
Yeah and put [ CODE ] [/ CODE ] around JUST the code not the whole post, like …
Jump to Post[edit]Sorry Holly I didn't see your last post when I posted this. The link you posted is a much better and thorough explaination.[/edit]
He he, well like they always say:
"Big red and firey, always late":lol:
All 8 Replies
WolfPack
491
Posting Virtuoso
Team Colleague
hollystyles
113
Veteran Poster
hollystyles
113
Veteran Poster
Ancient Dragon
5,243
Achieved Level 70
Team Colleague
Featured Poster
hollystyles
113
Veteran Poster
Iqbal_h_a
0
Light Poster
hollystyles
113
Veteran Poster
~s.o.s~
2,560
Failure as a human
Team Colleague
Featured Poster
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.