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 9224769
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T04:24:29+00:00 2026-06-18T04:24:29+00:00

Line 9 of the below code generates undefined behavior. Is this due to the

  • 0

Line 9 of the below code generates undefined behavior. Is this due to the fact that title1[] is outside of main() and is global? Or is it because something else that I’m missing?

1. char title1[]="The Name of the Rose";
2. Book book1={title1,900,0};
3. int main(){
4.   Book book2={"Foucault's Pendulum",1000,0};
5.   Book* book3=(Book*)malloc(sizeof(Book));
6.   *book3=book2;
7.   book1.next=&book2;
8.   book2.next=book3;
9.   book1.title[0]='B';
10.  book2.title[0]='A';
11.  {
12.    Book list[2];
13.    list[0]=book1;
14.    list[1]=book2;
15.    list[1].next->next=&book2;
16.    {
17.      Book* p=&list[0];
18.      while (p!=0) {
19.        p=p->next;
20.    }
21.  }
22. return 0;
23.}

EDIT:

Added the Book definition:

‫;‪struct Book‬‬
‪typedef struct Book‬ {
‫;‪  char* title‬‬
  int pages;‬‬
‫;‪  struct Book* next‬‬
‫;‪} Book‬‬
  • 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-18T04:24:30+00:00Added an answer on June 18, 2026 at 4:24 am

    No, line 9 is not undefined behavior. It writes to this array:

    char title1[]="The Name of the Rose";
    

    which is not a string literal (but initialized by one). Such a plain array can be modified to your liking. It would have been different if you would have declared it like this:

    char *title1="The Name of the Rose";
    

    The undefined behavior is in line 10, here you are writing into a string literal, which is not allowed.

    BTW, when asking a question here, please cook it down to a minimal example that shows your point. Most of the code you posted is completely useless for your question.

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

Sidebar

Related Questions

The code below produces a NumberFormatException in this line: val cache = cf.createCache(Collections.emptyMap()) Do
I have an R code block that generates an image (see below). Executing the
I have the line of code below... How would I modify it to insert
Executing the below code gives me the following exception on the last line: InvalidOperationException:
Why does the below code give Seg. Fault at last line? char* m=ReadName(); printf(\nRead
How can I line break OHAttributedLabel ? My below code didn't work. OHAttributedLabel *lbl
For some reason i'm getting an unexpected [ in the below line of code.
I'm trying to get from Line #1 to Line #2 in the below code:
Possible Duplicate: C++'s “placement new” in the below code what does Line 3 represents,
Line 3 of the code below fails if I omit the => $v portion.

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.