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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T00:36:07+00:00 2026-05-25T00:36:07+00:00

Possible Duplicates: Difference between char *str="STRING" and char str[] = "STRING"? Need some help

  • 0

Possible Duplicates:
Difference between char *str="STRING" and char str[] = "STRING"?
Need some help with C programming

while this snip gets segmentation fault

int main(void) {

    char*  str ="abcde";
    str[strlen(str)-1] ='\0';
    printf("%s",str);
    return 0;
}

If I put
char str [] ="abcde"; instead of the pointer that works perfectly, do you have an idea why so?

  • 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-05-25T00:36:08+00:00Added an answer on May 25, 2026 at 12:36 am

    When you write char *str = "abcde"; you make a char pointer to a string literal, which you are not allowed to modify.

    When you write char str[] = "abcde"; you make a char array and copy a string literal into it. This is just a normal char array so you are free to modify it.

    It is undefined behaviour to modify a string literal. This is a deliberate design decision that allows string literals to be placed in special read only sections of the output program. In practice many compliers and platforms do this (marking it read only means you need only one copy of the strings in memory, even if there is more than one instance of the program running). This leads to the behaviour you observed on your platform.

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

Sidebar

Related Questions

Possible Duplicates: Is there any difference between “string” and 'string' in Python? Single quotes
Possible Duplicate: Difference between WIN32 and other c string I got this code inside
Possible Duplicate: What is the difference between "typename" and "class" template parameters? When defining
Possible Duplicates: What is the difference between <% %> and <%=%>? C# MVC: What
Possible Duplicates: What is the difference between new/delete and malloc/free? In what cases do
Possible Duplicates: Why should we typedef a struct so often in C? Difference between
Possible Duplicates: SQL Server - bulk delete (truncate vs delete) What’s the difference between
Possible duplicates What is gcnew? What does the caret mean in C++/CLI? Difference between
Possible Duplicates: Difference between dates How to calculate the date difference between 2 dates
Possible Duplicates: C++ Virtual/Pure Virtual Explained What's the difference between virtual function instantiations in

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.