CFanatic

Go Back   CFanatic > Programming > C Programming

Join CFanatic Forum Now

Where does the string gets stored? topic posted under C Programming which is a part of Programming category in CFanatic Forum
Reply
 
Thread Tools Display Modes
  #1  
Old 09-10-2006, 10:32 AM
Junior Member
 
Join Date: Sep 2006
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
Iqbal_h_a is on a distinguished road
| More
Where does the string gets stored?

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
Reply With Quote
  #2  
Old 12-26-2006, 01:26 AM
Junior Member
 
Join Date: Dec 2006
Posts: 9
Thanks: 0
Thanked 0 Times in 0 Posts
Aztec is on a distinguished road
| More
Re: Where does the string gets stored?

Quote:
Originally Posted by Iqbal_h_a View Post
char *str="abcd"; // Where does this gets stored?
It's stored in a non-modifiable memory probably ROM.
Reply With Quote
  #3  
Old 12-26-2006, 02:44 AM
Junior Member
 
Join Date: Sep 2006
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
Iqbal_h_a is on a distinguished road
| More
Re: Where does the string gets stored?

Quote:
Originally Posted by Aztec View Post
It's stored in a non-modifiable memory probably ROM.
I could not get you.
Reply With Quote
  #4  
Old 12-26-2006, 03:21 AM
Junior Member
 
Join Date: Dec 2006
Posts: 9
Thanks: 0
Thanked 0 Times in 0 Posts
Aztec is on a distinguished road
| More
Re: Where does the string gets stored?

Quote:
Originally Posted by Iqbal_h_a View Post
I could not get you.
It simply means that you cannot modify the string since it's stored in some non-modifiable momory whereas your other one can by modified.
Reply With Quote
  #5  
Old 12-26-2006, 07:20 AM
Junior Member
 
Join Date: Sep 2006
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
Iqbal_h_a is on a distinguished road
| More
Re: Where does the string gets stored?

Quote:
Originally Posted by Aztec View Post
It simply means that you cannot modify the string since it's stored in some non-modifiable momory whereas your other one can by modified.
But I can modify it.
Reply With Quote
  #6  
Old 12-26-2006, 07:23 AM
Junior Member
 
Join Date: Dec 2006
Posts: 9
Thanks: 0
Thanked 0 Times in 0 Posts
Aztec is on a distinguished road
| More
Re: Where does the string gets stored?

Quote:
Originally Posted by Iqbal_h_a View Post
But I can modify it.
You are not allowed to modify that. If you do that, results are unpredicatable i.e it may work or it may not work. You should not do that.
Reply With Quote
  #7  
Old 03-18-2008, 10:29 AM
Junior Member
 
Join Date: Mar 2008
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
heavensgate15 is on a distinguished road
| More
Post Re: Where does the string gets stored?

Hmm.. I'm not sure but I think it depends. If *str is holding an address which is located in the heap, then, it will be stored in the heap. But if *str is holding an address which is located in stack, then, the value will be stored in stack...
Reply With Quote
  #8  
Old 07-31-2008, 04:24 PM
Senior Member
 
Join Date: Jul 2008
Posts: 101
Thanks: 0
Thanked 0 Times in 0 Posts
xpi0t0s is on a distinguished road
| More
Re: Where does the string gets stored?

It's stored in the program static data area, sometimes known as BSS. This is static data that you MUST NOT modify (all being well you will be prevented anyway). It's not stored in ROM, it's stored in RAM, but it shouldn't be changed because you will get undefined behaviour.
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Multibyte string conversions rajeshgalla C Programming 4 12-07-2010 07:40 AM
How to insert a string into string? Tran C Programming 3 05-21-2008 09:51 PM
string to double kimw C Programming 1 12-26-2006 01:25 AM
rotate string iwdu15 C# Programming 0 09-29-2006 12:48 AM

 

Advertisement

CFanatic Search
Custom Search

Advertisement

All times are GMT -5. The time now is 02:04 AM.



Powered by vBulletin® Version 3.7.4
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO ©2010, Crawlability, Inc.
Cfanatic.com is a premier member of the IDG TechNetwork. For advertising opportunities contact here
Get Paid for Working on Projects Matching Your Expertise at Go4Expert's Jobs Board