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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T04:55:38+00:00 2026-06-17T04:55:38+00:00

The code is self-explanatory, but it gives me segmentation fault, why? :\ #include <stdio.h>

  • 0

The code is self-explanatory, but it gives me segmentation fault, why? :\

#include <stdio.h>
int main(void)
{
    char *c = "Hella";
    *(c+4) = 'o';
    printf("%s\n",c);
}
  • 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-17T04:55:40+00:00Added an answer on June 17, 2026 at 4:55 am

    How to avoid it?

    Don’t modify a string literal!

    char *c = "Hella";
    

    Declares a pointer c to a string literal “Hella” stored in implementation defined read only memory.
    You are not allowed to modify this literal. An attempt to do so results in Undefined Behavior.

    You are lucky that your program crashes, an Undefined Behavior does not always result in a crash but may cause your program to behave weirdly in any possible way.

    What you need here is an array:

    char c[] = "Hella";
    

    Good Read:
    What is the difference between char a[] = ?string?; and char *p = ?string?;?

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

Sidebar

Related Questions

I think this code and error is self-explanatory, but I don't know why? Environment:
I hope following sample code is self-explanatory: declare @t1 table (ID int,Price money, Name
The following code is fairly self explanatory, but I am running in to an
Should be pretty self-explanatory, but this is in the context of real-time XNA code
Topic is self explanatory. I found xaml code to do it for an Expander,
The comments in the code should be self explanatory. <div id=pad2></div> <input id=oscPitch type=range
As my title is self explanatory, I know how to rectify it but why
The following code is probably self explanatory Lists number of active subscribers 1st of
The following code is pretty self-explanatory and my question is very simple : Why
I think the bug's pretty self-explanatory, so I'll just post the code and a

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.