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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T20:20:57+00:00 2026-06-09T20:20:57+00:00

char * str = Hello; *(str+1) = ‘3’; cout<<str; What I was trying to

  • 0
char * str = "Hello";

*(str+1) = '3';

cout<<str;

What I was trying to do there was to change the second character into ‘3’, turning it into H3llo

Why doesn’t it work?

  • 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-09T20:20:58+00:00Added an answer on June 9, 2026 at 8:20 pm

    This is undefined behaviour. You cannot change literal.

    To have a pointer to literal, it should be:

      const char* str = "Hello";
    //^^^^^
    

    Then, to be able to change string, this should be, for example

    char str[] = "Hello";
    

    The other option is to allocate dynamically the memory (using malloc and free)

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

Sidebar

Related Questions

Hello Can somebody explain why second cout in func(char *p) doesn't work: #include <cstdlib>
see char str[] = hello world; printf(%s,str); printf statement prints the all character in
I have a string as const char *str = Hello, this is an example
Will this leak memory? char *str = Hello/World; char *pos = rindex(str, '/'); *pos
If I change the type to const char str[Len] , I get the following
Consider the following code: char* str = Hello World; memcpy(str, Copy\0, 5); A segmentation
I have the following code in C: char *str = Hello World; char *s
I have this in an exercise with pointers: char *str = Hello; int count
Can anyone explain this to me , String str = Hello; str += ((char)97)
char str[]=Hello; this allocates 6 bytes for the string , but if i write

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.