943,880 Members | Top Members by Rank

Ad:
  • C Discussion Thread
  • Unsolved
  • Views: 1661
  • C RSS
Sep 7th, 2006
-1

Where does the string gets stored?

Expand Post »
  1. Please look at the following code snippets:
  2.  
  3. char str[]="abcd"; // Gets stored in stack frame.
  4.  
  5. char *str="abcd"; // Where does this gets stored?
  6.  
  7.  
  8. 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.
  9.  
  10.  
  11. Thanks
  12. Iqbal
Last edited by Iqbal_h_a; Sep 7th, 2006 at 8:12 am.
Similar Threads
Reputation Points: 51
Solved Threads: 1
Light Poster
Iqbal_h_a is offline Offline
30 posts
since Aug 2006
Sep 7th, 2006
1

Re: Where does the string gets stored?

Please post your question outside code tags. I corrected your first two posts, do this one yourself, or I will delete this thread. Since it has been only 2 minutes since your post, you can edit it now.
Moderator
Reputation Points: 572
Solved Threads: 115
Mentally Challenged Mod.
WolfPack is offline Offline
1,559 posts
since Jun 2005
Sep 7th, 2006
2

Re: Where does the string gets stored?

Quote ...
(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 Wolpack said please.
Last edited by hollystyles; Sep 7th, 2006 at 8:22 am.
Reputation Points: 262
Solved Threads: 68
Veteran Poster
hollystyles is offline Offline
1,181 posts
since Feb 2005
Sep 7th, 2006
1

Re: Where does the string gets stored?

Wolfpack just gave me this URL
http://www.daniweb.com/techtalkforums/thread50780.html

Moral:
Search the forums before posting.
Last edited by hollystyles; Sep 7th, 2006 at 8:34 am.
Reputation Points: 262
Solved Threads: 68
Veteran Poster
hollystyles is offline Offline
1,181 posts
since Feb 2005
Sep 7th, 2006
0

Re: Where does the string gets stored?

>>char *str="abcd";

There are two objects here -- the pointer itself is a variable that is on the stack. It contains the address of the string that is stored in the heap -- often in read-only memory.

[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]
Last edited by Ancient Dragon; Sep 7th, 2006 at 8:38 am.
Sponsor
Team Colleague
Featured Poster
Reputation Points: 5608
Solved Threads: 2282
Retired and Enjoying Life
Ancient Dragon is offline Offline
21,952 posts
since Aug 2005
Sep 7th, 2006
2

Re: Where does the string gets stored?

Quote ...
[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:
Last edited by hollystyles; Sep 7th, 2006 at 10:10 am.
Reputation Points: 262
Solved Threads: 68
Veteran Poster
hollystyles is offline Offline
1,181 posts
since Feb 2005
Sep 8th, 2006
1

Re: Where does the string gets stored?

Click to Expand / Collapse  Quote originally posted by WolfPack ...
Please post your question outside code tags. I corrected your first two posts, do this one yourself, or I will delete this thread. Since it has been only 2 minutes since your post, you can edit it now.
Sorry for my ignorance. As I am new to this blog, I was unaware of the rules.
I tried to edit the post as you suggested, but could not do so.
I will definitely take care of all the rules in my future posts.
I am extremely sorry if I hurt anybody by breaking the rules.
Thanks
Iqbal
Reputation Points: 51
Solved Threads: 1
Light Poster
Iqbal_h_a is offline Offline
30 posts
since Aug 2006
Sep 8th, 2006
1

Re: Where does the string gets stored?

Quote ...
Sorry for my ignorance. As I am new to this blog, I was unaware of the rules.
I tried to edit the post as you suggested, but could not do so.
I will definitely take care of all the rules in my future posts.
I am extremely sorry if I hurt anybody by breaking the rules.
Thanks
Iqbal
It's ok it doesn't hurt too much he he
anyway at least we know you got the message now.

Of course we don't expect you to know all the rules straight off. If you look in my signature there's a link to 'the basics', I recommend reading that it will help you to make good posts that will get read and answered. Forums are a bit like Ebay you gotta put some effort into the listing to get bids and a sale, same here to get good answers.

Lastly don't mind WolfPack he's a big softy really, but he has the onerous responsibility of being a moderator and keeping everyone in line and the threads looking neat and tidy, so he has to throw his weight around a litte otherwise everyone would just ignore him, and the forum would be an unsightly mess. The knowledgeable people with all the answers only come and stay and answer posts in nice neat forums so the effort is worth it I think.
Last edited by hollystyles; Sep 8th, 2006 at 4:59 am. Reason: typos
Reputation Points: 262
Solved Threads: 68
Veteran Poster
hollystyles is offline Offline
1,181 posts
since Feb 2005
Sep 8th, 2006
1

Re: Where does the string gets stored?

Click to Expand / Collapse  Quote originally posted by Iqbal_h_a ...
Sorry for my ignorance. As I am new to this blog, I was unaware of the rules.
I tried to edit the post as you suggested, but could not do so.
I will definitely take care of all the rules in my future posts.
I am extremely sorry if I hurt anybody by breaking the rules.
Thanks
Iqbal
As long as you learn from your mistakes, everyone is happy about it. And btw welcome to the forums. Just be kind enough to respect other ppl out here and i am sure you would get all the help you require.

Keep rocking....
Super Moderator
Featured Poster
Reputation Points: 3233
Solved Threads: 719
Failure as a human
~s.o.s~ is offline Offline
8,871 posts
since Jun 2006

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C Forum Timeline: how to make utilize of system( ) function
Next Thread in C Forum Timeline: glut





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC