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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T04:37:07+00:00 2026-06-14T04:37:07+00:00

void changeStr(char *str) { str = D; } void changeStr(char **str) { *str =

  • 0
void changeStr(char *str)
{
    str = "D";
}

void changeStr(char **str)
{
    *str = "S";
}

    char str[] = "Good";
    changeStr(str); 
    cout<<str<<endl;
    char *p = str;
    //*p = 'j';
    changeStr(&p);
    cout<<str<<endl;

I just try to change the value of str[] that array. WITHOUT RETURN!

I think the first changeStr just pass in pointer of str, and change that value, but actually it did not change it.

The second I use pointer of pointer but also cannot 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-14T04:37:08+00:00Added an answer on June 14, 2026 at 4:37 am

    Let’s take it step by step.

    char str[] = "Good";
    

    You are creating an array of characters, 5 characters long with the following content:

    { 'G', 'o', 'o', 'd', '\0' }

    changeStr(str);
    

    Here, you are passing that array to a function. Since arrays decay into pointers, this call is perfectly OK.

    void changeStr(char *str)
    {
        str = "D";
    }
    

    Now, here comes the first issue. You are probably confusing "D" and 'D'. If you want to change the first character in the array you need to do it the following way:

    str[0] = 'D';
    

    This would work fine. Changing the pointer won’t do anything, because it’s a local variable that holds a pointer to the beginning of the array, not the array itself. If you want to replace the entire content of the array with just { 'D', '\0' }, you would need to use strcpy.

    strcpy(str,"D");
    

    Now, let’s check the last part. Here you mix things up a bit.

    char *p = str;
    changeStr(&p);
    

    You are creating a new variable that points to the beginning of the array and you pass pointer to that variable into the next function.

    void changeStr(char **str)
    {
        *str = "S";
    }
    

    Which does indeed change the original variable passed, but remember, this is p not the array. What you did is change where p points. It now points to a constant "S".

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

Sidebar

Related Questions

Add next changes: Emily::oSeMac^ Terminal; Emily::AsyncSocketController^ _socketManager; delegate void DataArrival(String^, array<unsigned char, 1>^, System::Net::IPEndPoint^);
If i have char* str; how do I write a function that accepts str
Possible Duplicate: std::vector<std::string> to char* array I have to call a c function that
void test() { unsigned char c; c = (~0)>>1 ; printf(c is %u\n,c); }
I am porting cpp code to Objective C. In cpp void create(INT32u &uLen) {
void distinct (void) { char sent; int n1, n2, n3, n4, n5, n6, n7;
Just wondering if someone could explain this to me? I have a program that
extern C _declspec(dllexport)void Export3DS(const char* inputname,const char* Objname,const char* mtlname); I am using vs2008
I want to pass a char ** pointer by value. Given the following code:
AFunc changes what was sent to it, and the printf() outputs the changes: void

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.