Advertisement

07.19.2008 at 08:11PM PDT, ID: 23579686
[x]
Attachment Details

Question on the C99 standard

Asked by josgood in C Programming Language, C++ Programming Language

Tags: C99, pionter, array

I have this old fixed idea, probably acquired in the dawn ages of K&R, that something like
   char *str = "123";
   *str = '0';
is OK and will set *str to "023".  

Clearly I am wrong, but I can't find anything in the C99 standard that says so.  

I am aware that
   char str[] = "123";
   *str = '0';
works fine.

Given that pointer notation and array notation are two syntactic ways of performing the same semantic tasks,
why is one treated as a pointer to a const literal and the other treated as modifiable data?

I've looked in the C99 standard, but haven't found a good reference.

Have you one?
Start Free Trial
[+][-]07.19.2008 at 09:35PM PDT, ID: 22044586

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]07.19.2008 at 09:53PM PDT, ID: 22044610

View this solution now by starting your 7-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

 

About this solution

Zones: C Programming Language, C++ Programming Language
Tags: C99, pionter, array
Sign Up Now!
Solution Provided By: ozo
Participating Experts: 3
Solution Grade: A
 
 
[+][-]07.19.2008 at 10:29PM PDT, ID: 22044663

Assisted solutions are selected by the member who asked the question as a comment that contributed to their question's solution.

Start your 7-day free trial to view this Assisted Solution or ask the Experts your question.

 
[+][-]07.19.2008 at 10:49PM PDT, ID: 22044686

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]07.20.2008 at 02:10AM PDT, ID: 22045036

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
 
Loading Advertisement...
20080716-EE-VQP-32 / EE_QW_EXPERT_20070906