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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T07:51:47+00:00 2026-05-13T07:51:47+00:00

Possible Duplicate: Why does simple C code receive segmentation fault? Hey Everyone, I’m sure

  • 0

Possible Duplicate:
Why does simple C code receive segmentation fault?

Hey Everyone, I’m sure this is a very basic question, but apparently I’m not quite understanding something here.

I’ve been playing around with C a lot over winter break and just came across something that I thought would work but is giving me a segmentation fault.

if I declare a string as:
char name[5] = “Mike”;
I can manipulate the string: *(name+1) = ‘a’; This works fine, name becomes “Make”.

If I declare as:
char *name = “Mike”;
and then try the same thing: *(name+1) = ‘a’; I get a segmentation fault. Why can’t I do that?

If I malloc the space for the string: char *name = (char*)malloc(5*sizeof(char)); and then copy the string to name: strcpy(name,”Mike”); I can manipulate it like above just fine. *(name+1) = ‘a’; works.

What is the difference between char *name = “Mike”‘, and char *name = (char*)malloc(5*sizeof(char)); strcpy(name,”Mike”);? Aren’t they both just pointing to memory containing the string?

Sorry for the noobish question!

  • 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-13T07:51:48+00:00Added an answer on May 13, 2026 at 7:51 am

    char name[5] = "Mike" declares a local array and copies the string “Mike” into it. char* name = "Mike" assigns a pointer to “Mike” without copying. In both cases, “Mike” is a constant string held in a read-only page, and so in the second case you are trying to modify the original constant.

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

Sidebar

Ask A Question

Stats

  • Questions 377k
  • Answers 377k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Use Me.Close() to hide the form. To open it, use… May 14, 2026 at 8:52 pm
  • Editorial Team
    Editorial Team added an answer It's not the Finder making these connections—network filesystems are mounted… May 14, 2026 at 8:52 pm
  • Editorial Team
    Editorial Team added an answer If you're using Zend Framework, I highly suggest you just… May 14, 2026 at 8:52 pm

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.