This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

How to make a pointer point to a constant string in RAM

I'm using Keil3 for arm.
1\I wanna change the string's content,eg from "2007" to "2008"
2\I wanna a pointer ,not a array,to point to the string.
But when I do as follows:
char *ptr = "2007";
ptr is in the flash area,so I cann't change the content of the string "2007" .

Parents
  • char array[]="2007";//global variable
    char *ptr=array;
    

    But ptr is superfluous, isn't it?

    In what situation would you need 'ptr' that you couldn't use 'array' directly?

    Sounds like you need to review the very close similarities between array names & pointers in 'C'...

Reply
  • char array[]="2007";//global variable
    char *ptr=array;
    

    But ptr is superfluous, isn't it?

    In what situation would you need 'ptr' that you couldn't use 'array' directly?

    Sounds like you need to review the very close similarities between array names & pointers in 'C'...

Children