-2

Possible Duplicate:
What is the difference between char s[] and char *s in C?
What is the difference between char a[] = “string”; and char *p = “string”;

I want to know what is difference between below two string declaration in C language

char *myString = "This is a C character string";

and

char myString[] = "This is a C character array";

I know that first one is pointer and second is array but i couldn't get the difference.

Community
  • 1
  • 1
JavaGeek
  • 1,535
  • 9
  • 39
  • 63

1 Answers1

1

In addition to Binyamin Sharet's answer, in the first case you can change the myString pointer, but in the second case you can't. So, this code will compile and run and print "ello":

#include <stdio.h>

int main(int argc, char **argv)
{
    char *myString = "Hello\n";

    myString++;

    printf("%s", myString);
}

But this code won't compile:

#include <stdio.h>

int main(int argc, char **argv)
{
    char myString[] = "Hello\n";

    myString++;

    printf("%s", myString);
}
srgerg
  • 18,719
  • 4
  • 57
  • 39