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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T12:46:12+00:00 2026-05-21T12:46:12+00:00

#include <stdio.h> #include <string.h> main() { char tmpChar; char *str_1 = Hello; int index;

  • 0
#include  <stdio.h>
#include  <string.h>

main()
{
    char tmpChar;
    char *str_1 = "Hello";

    int index;
    int len = strlen(str_1);
    for (int i = 0; i < len/2; i++)
    {
        index = len - 1- i;
        tmpChar = str_1[len - i -1];
        str_1[index] = str_1[i]; <<<<<--------------- core dumps at this point. Not sure why
        str_1[i] = tmpChar;
        printf("str_1[%d] = %c\n", i, str_1[i]);
    }
    str_1[len] = '\0';
    printf("str_1 = %s\n", str_1);
}
  • 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-21T12:46:13+00:00Added an answer on May 21, 2026 at 12:46 pm

    The ISO C99 standard has this to say about string literals (section 6.4.5/6):

    It is unspecified whether these arrays are distinct provided their elements have the
    appropriate values. If the program attempts to modify such an array, the behavior is
    undefined.

    That’s because, typically, all the string literals are lumped into a single area which may be marked read-only, and they’re sometimes merged to save space. In other words, the two string literals:

    char *p1 = "Googolplex";
    char *p2 = "plex";
    

    may be stored thus:

      +--- p1           p2 ---+
      |                       |
      V                       V
    +---+---+---+---+---+---+---+---+---+---+----+
    | G | o | o | g | o | l | p | l | e | x | \0 |
    +---+---+---+---+---+---+---+---+---+---+----+
    

    That means: don’t try to modify them. It may work under certain situations but it’s not something that you should rely on if you value portability even a little.

    Change:

    char *str_1 = "Hello";
    

    to:

    char str_1[] = "Hello";
    

    since this is effectively the same as:

    char str_1[6];
    strcpy (str_1, "Hello");
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

#include <stdio.h> #include <stdlib.h> #include <string.h> int main() { char *a = Hello ;
Code : #include stdio.h #include string.h int main() { char *p = abc; printf(p
#include<stdio.h> int main() { char *p=mystring; return 0; } String literal mystring, where will
/* strchr example */ #include <stdio.h> #include <string.h> int main () { char str[]
I just translated this program, #include <stdio.h> int dam[1000][1000]; int main (int argc, const
Consider the following code: #include <stdio.h> #include <ctype.h> char* Mstrupr(char* szCad); int main() {
I have this piece of code #include <stdio.h> #include <stdlib.h> #include <stdint.h> #include <string.h>
#include <stdio.h> int main() { unsigned long long int num = 285212672; //FYI: fits
Test the following code: #include <stdio.h> #include <stdlib.h> main() { const char *yytext=0; const
Can anyone explain to me why this isn't working? #include <stdio.h> #include <stdlib.h> char

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.