473,788 Members | 2,868 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

char *s = "Google"

char *s = "Google"

Where this "Google" will be stored?
Why it can't be changed?
like s[1]='h'; -this is giving error
please explain this.

Dec 13 '06 #1
15 1824
Le 13-12-2006, Sri Ragaventhirar <sr************ ***@gmail.coma écrit*:
char *s = "Google"

Where this "Google" will be stored?
Somewhere you are not allowed to write in.
Why it can't be changed?
No.
like s[1]='h'; -this is giving error
please explain this.
You are trying to write in a forbiden place.
What you can do is:
char s[]= "Google";
and then, you are allowed to do
s[1]= 'h';

Marc Boyer
Dec 13 '06 #2
On 13 Dec 2006 00:55:28 -0800, "Sri Ragaventhirar"
<sr************ ***@gmail.comwr ote:
>char *s = "Google"

Where this "Google" will be stored?
Why it can't be changed?
like s[1]='h'; -this is giving error
please explain this.
The answer is in FAQ 1.32.

http://c-faq.com/decl/strlitinit.html

--
jay
Dec 13 '06 #3
where this string "google"wil l be stored?
why it can't be changed?

Dec 13 '06 #4
where this string "google"wil l be stored?
why it can't be changed?

Dec 13 '06 #5
Le 13-12-2006, Sri Ragaventhirar <sr************ ***@gmail.coma écrit*:
where this string "google"wil l be stored?
It depends on your platform, ie which compiler, which options,
which OS...
why it can't be changed?
Because the standard states that...
Why the standard did this choice ? I assume this is to allow
this kind of string to be stored in read-only memory, which
could be cheaper in some platform...

Marc Boyer
Dec 13 '06 #6
thank you for your info
--------------------------------
Anywhere else, it turns into an unnamed, static array of characters,
and this unnamed array may be stored in read-only memory, and which
therefore cannot necessarily be modified. In an expression context, the
array is converted at once to a pointer, as usual (see section 6), so
the second declaration initializes p to point to the unnamed array's
first element.
-------------------------------
can you explain more about this read only memory(why it is like that
and where it is actually stored)(code segment data segment, stactk
segment???)

Dec 13 '06 #7
Sri Ragaventhirar wrote:
thank you for your info
--------------------------------
Anywhere else, it turns into an unnamed, static array of characters,
and this unnamed array may be stored in read-only memory, and which
therefore cannot necessarily be modified. In an expression context, the
array is converted at once to a pointer, as usual (see section 6), so
the second declaration initializes p to point to the unnamed array's
first element.
-------------------------------
can you explain more about this read only memory(why it is like that
and where it is actually stored)(code segment data segment, stactk
segment???)
It's like that because it is a string literal. It should require const
char*, but const is broken due to backwards compatibility in C.

Where its is stored is up to the implementation.

--
Ian Collins.
Dec 13 '06 #8
Sri Ragaventhirar wrote:

(several times. DON'T DO THAT. We are not a chatgroup.)
char *s = "Google"

Where this "Google" will be stored?
Somewhere that lasts from when the program starts to when it
ends. (Maybe even longer, but you can't tell.)
Why it can't be changed?
You don't know if it can or can't be. All you know is that
trying to change it gets undefined behaviour: in other words,
the implementation can do whatever it likes.
like s[1]='h'; -this is giving error
please explain this.
What kind of error? A compile-time error or a run-time one?

The compiler may choose to store the string in a region of
read-only memory. That memory may cause an signal to be raised
if you try and change it. BOOM.

The compiler may choose to store the string in a region of
read-only memory. That memory may ignore any attempt to change
it.

The compiler may choose to store the string in a region of
writeable memory. Assigning to elements of the string will
update it.

The compiler may choose to store the string in a region of
read-only memory. Writing to that memory may cause a
hedgehog to come and sign in your ear. Badly.

All four of these are legitimate implementations - even the
fourth, although the shortage of singing hedgehogs makes
it less likely you'll encounter it.

So don't assign into string literals.

--
Chris "We are BROKE-en" Dollin
"We did not have time to find out everything we wanted to know."
- James Blish, /A Clash of Cymbals/

Dec 13 '06 #9
Sri Ragaventhirar wrote:
thank you for your info
--------------------------------
Anywhere else, it turns into an unnamed, static array of characters,
and this unnamed array may be stored in read-only memory, and which
therefore cannot necessarily be modified. In an expression context, the
array is converted at once to a pointer, as usual (see section 6), so
the second declaration initializes p to point to the unnamed array's
first element.
-------------------------------
can you explain more about this read only memory(why it is like that
and where it is actually stored)(code segment data segment, stactk
segment???)
It's stored somewhere the implementation decides, wherever it's convenient.
Generally speaking one shouldn't need to care. If one /does/ care, one
consults one's local documentation or implementation-specific newsgroup.

Why do you care?

--
Chris "Perikles triumphant" Dollin
"Life is full of mysteries. Consider this one of them." Sinclair, /Babylon 5/

Dec 13 '06 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
4207
by: Alastair | last post by:
Hello guys, I've been building a search facility for an intranet site I'm part of developing and we've been building a search engine using Index Server. It mostly works, however there have been a few niggling problems and fixing it seems to be a case of patching errors as we find them so I'm thinking that it might be worth starting the logic from scratch and rebuilding this again. Basically we have a simple search, which is simply a...
87
5262
by: ziliath | last post by:
I recently tried out the Google "top coder" contest, as a C++ coder. I noticed immediately that they expected me to know STL. To which I say, what the fuck?! I may be missing something, but at what point when learning C++ was I supposed to have picked up STL? I ask because at every job I've had, and every job interview for that matter, whenever STL comes up it's not I, but a manager who says effectively yuck, we don't use that crap.
5
2078
by: junky_fellow | last post by:
Each time i submit some pattern to "google", it shows search took 0.XX seconds for exploring millions of web pages. When i look for efficient ways of searching a string, they always say compare your string with the strings in the file one by one. if there are millions of web pages then these algorithms would take considerable amount of time. So, what does google do for searching a pattern. Does it use thousands of parallel computers...
2
1266
by: Phin | last post by:
Hi, I would like to have the "google suggests" functionality on a web page like it is here: http://www.google.com/webhp?complete=1&hl=en I have downloaded the AJAX .NET wrapper (http://ajax.schwarz-interactive.de/csharpsample/default.aspx) and viewed the video and the example but I still don't know how to get the
4
3391
by: Stef Mientki | last post by:
hello, In a program I want to download (updated) files from google code (not the svn section). I could find a python script to upload files, but not for downloading. Anyone has a hint or a solution ? thanks,
0
9656
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10366
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10175
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10112
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8993
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7518
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
1
4070
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3675
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2894
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.