Where does the string gets stored?

Reply

Join Date: Aug 2006
Posts: 29
Reputation: Iqbal_h_a is an unknown quantity at this point 
Solved Threads: 1
Iqbal_h_a Iqbal_h_a is offline Offline
Light Poster

Where does the string gets stored?

 
-1
  #1
Sep 7th, 2006
  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 7:12 am.
Reply With Quote Quick reply to this message  
Join Date: Jun 2005
Posts: 1,496
Reputation: WolfPack has a spectacular aura about WolfPack has a spectacular aura about WolfPack has a spectacular aura about 
Solved Threads: 104
Moderator
WolfPack's Avatar
WolfPack WolfPack is offline Offline
Mentally Challenged Mod.

Re: Where does the string gets stored?

 
1
  #2
Sep 7th, 2006
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.
バルサミコ酢やっぱいらへんで
Reply With Quote Quick reply to this message  
Join Date: Feb 2005
Posts: 1,181
Reputation: hollystyles will become famous soon enough hollystyles will become famous soon enough 
Solved Threads: 67
hollystyles's Avatar
hollystyles hollystyles is offline Offline
Veteran Poster

Re: Where does the string gets stored?

 
2
  #3
Sep 7th, 2006
(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 7:22 am.
==========================================
Yadda yadda yadda...
Web junky, fevered monkey
Reply With Quote Quick reply to this message  
Join Date: Feb 2005
Posts: 1,181
Reputation: hollystyles will become famous soon enough hollystyles will become famous soon enough 
Solved Threads: 67
hollystyles's Avatar
hollystyles hollystyles is offline Offline
Veteran Poster

Re: Where does the string gets stored?

 
1
  #4
Sep 7th, 2006
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 7:34 am.
==========================================
Yadda yadda yadda...
Web junky, fevered monkey
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 16,601
Reputation: Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute 
Solved Threads: 1614
Team Colleague
Featured Poster
Ancient Dragon's Avatar
Ancient Dragon Ancient Dragon is offline Offline
Still Learning

Re: Where does the string gets stored?

 
0
  #5
Sep 7th, 2006
>>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 7:38 am.
Reply With Quote Quick reply to this message  
Join Date: Feb 2005
Posts: 1,181
Reputation: hollystyles will become famous soon enough hollystyles will become famous soon enough 
Solved Threads: 67
hollystyles's Avatar
hollystyles hollystyles is offline Offline
Veteran Poster

Re: Where does the string gets stored?

 
2
  #6
Sep 7th, 2006
[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 9:10 am.
==========================================
Yadda yadda yadda...
Web junky, fevered monkey
Reply With Quote Quick reply to this message  
Join Date: Aug 2006
Posts: 29
Reputation: Iqbal_h_a is an unknown quantity at this point 
Solved Threads: 1
Iqbal_h_a Iqbal_h_a is offline Offline
Light Poster

Re: Where does the string gets stored?

 
1
  #7
Sep 8th, 2006
Originally Posted by WolfPack View Post
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
Reply With Quote Quick reply to this message  
Join Date: Feb 2005
Posts: 1,181
Reputation: hollystyles will become famous soon enough hollystyles will become famous soon enough 
Solved Threads: 67
hollystyles's Avatar
hollystyles hollystyles is offline Offline
Veteran Poster

Re: Where does the string gets stored?

 
1
  #8
Sep 8th, 2006
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 3:59 am. Reason: typos
==========================================
Yadda yadda yadda...
Web junky, fevered monkey
Reply With Quote Quick reply to this message  
Join Date: Jun 2006
Posts: 7,768
Reputation: ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of 
Solved Threads: 493
Super Moderator
Featured Poster
~s.o.s~'s Avatar
~s.o.s~ ~s.o.s~ is offline Offline
Failure as a human

Re: Where does the string gets stored?

 
1
  #9
Sep 8th, 2006
Originally Posted by Iqbal_h_a View Post
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....
I don't accept change; I don't deserve to live.

Sacrifice is a painful, pure and beautiful thing.

Dammit, Jones, What the Hell Are Knoll Pointers?!
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:




Views: 1481 | Replies: 8
Thread Tools Search this Thread



Tag cloud for C
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2010 DaniWeb® LLC