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

  • Home
  • SEARCH
  • 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 8305251
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T18:04:08+00:00 2026-06-08T18:04:08+00:00

In the K&R book page 104, I came across this statement: char amessage[] =

  • 0

In the K&R book page 104, I came across this statement:

char amessage[] = "now is the time"; //an array
char *pmessage = "now is the time";  //a pointer

Individual characters within the array may be changed but amessage
will always refer to the same storage. The pmessage pointer may
subsequently be modified to point elsewhere, but the result is
undefined if you try to modify the string contents…

So, would this be the error they meant in both cases?

For the array,

amessage[] = "allocate to another address"; //wrong?

For the pointer,

pmessage[0] = 'n'; //wrong?

I just want to know when one is going against these rules.

Thanks.

  • 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-08T18:04:10+00:00Added an answer on June 8, 2026 at 6:04 pm
    /* OK, modifying an array initialized by the 
     * elements of a string literal */
    amessage[0] = 'n';
    
    /* not OK, modifying a string literal.
     * String literals are non-modifiable */
    pmessage[0] = 'n';
    

    Note that in C you cannot assign arrays, so if you want to copy an array use memcpy function or use strcpy function to copy a string.

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

Sidebar

Related Questions

I came across this in the book: wscanf(L%lf, &variable); where the first parameter is
I recently bought Bob's book Delphi XML, SOAP & Web Services in page 85
We have a Face book page.We add a custom FBML tab.Now we want to
I am reading K&R book, on page 63 there is a line while (--lim
i just was asking about the existence of a headfirst book(iPhone&iPad development) which covers
Code in the book Beginning iPhone Development (by Dave Mark & Jeff LaMarche) assigns
In K&R ANSI C book, section A.7.4.5 (Unary Minus Operator) it is stated: ...
While solving exercises from the K&R C book, I stumbled upon the exercise 2.1.
All, I'm going through the Friedman & Felleisen book A Little Java, A Few
My page's url is rewritten like so, www.test-me.com/book-cat-white.HTML book is book.php cat is animal=cat

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.