Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7763683
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T14:43:13+00:00 2026-06-01T14:43:13+00:00

I believe that in C99, modification of string literals is undefined behaviour. I don’t

  • 0

I believe that in C99, modification of string literals is undefined behaviour. I don’t have a copy of that standard but I do have a draft of C1X (n1570) which states in 6.4.5 paragraph 7:

It is unspecified whether these arrays are distinct provided their elements have the
appropriate values. If the program attempts to modify such an array, the behavior is
undefined.

I have found a Stack Overflow question that touches on this topic and contains the following comment from Jonathan Leffler:

Originally, the C89 (C90) standard did not outlaw modifying literals because there was too much code written before the standard that would be broken by it.

But I have also seen lots of discussion of the type of string literals and the fact that they are char[N] and not const char[N]. I gather that this decision was taken so that the large body of existing code would not break.

Can anyone give me a definitive answer. Is string literal modification UB in C89?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T14:43:15+00:00Added an answer on June 1, 2026 at 2:43 pm

    Yes, they are non-modifiable in C89.

    (C90, 6.1.4) "If the program attempts to modify a string literal of either form, the behavior is undefined"

    Even in K&R 2nd edition, there are quotes regarding the immutability of string literals.

    (K&R2, 5.5) "the result is undefined if you try to modify the string contents"

    (K&R2, Appendix C) "Strings are no longer modifiable, and so may be placed in read-only memory"

    In the ANSI C89 Rationale, there is an explanation of why it is non-modifiable:

    (ANSI C89 Rationale, 3.1.4) "String literals are specified to be unmodifiable. This specification allows implementations to share copies of strings with identical text, to place string literals in read-only memory, and perform certain optimizations."

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I don't believe that I am using any 3.0 specific APIs, but somehow whenever
I believe that most of you have heard of preloading of images. But is
I believe that i have followed the documentation on SendGrid's site but so far
I have been lead to believe that it is possible to pass a class
I believe that out there we have algorithms implementations (e.g. a c++ implementation of
I believe that all the problems that have iterative logic can be solved using
I believe that the C++ standard for std::sort does not guarantee O(n) performance on
I believe that the main thread cannot die before the child thread. But is
I believe that I have successfully impersonated my own user account while running an
I believe that I am dealing with some DLL hell. I have a reference

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.