0

I have a string constant that is assigned to a variable, like this:

const char* a = "Programming";

And I want to copy it to another variable of const char*, something like:

const char* b;

Here, I have tried memcpy() and strcpy(); it's not working, because in memcpy and strcpy, the destination variable should be char* instead of const char*. How do I get a copy of a const char*?

Neil
  • 1,767
  • 2
  • 16
  • 22
atla praveen
  • 49
  • 1
  • 4

1 Answers1

3

move the pointer ?

int main(){
    const char* a = "Programming";
    const char* b;

    //copy a to b
    b = a;

    printf("%s\n", b);


}
Matth B
  • 64
  • 1
  • 4
  • 1
    They will both point to the same memory, so technically it is *copy* instead of *move*. – Neil Jun 02 '22 at 07:21