Explain the difference between the C pointer array and the Char character array

  • 2020-05-30 20:50:22
  • OfStack

Explain the difference between an Char pointer array and a character array in the C language

1. Pointer array of type char: each element points to a string, which can be changed


char *name[3] = {
  "abc",
  "def",
  "gbk"
  };
for(int i = 0 ; i < strlen(name); i ++) { 
   printf("%s\n", *(name+i));
   //printf("%s\n", name[i]);
 } 

// To change 
name[3] = {
"aaa",
"bbb",
"ccc"
}

2. Character array: the point cannot be changed, but the value inside can be changed


char names[] =  " abc " ; 
names[2] =  ' D';

If you have any questions, please leave a message or come to the site community to exchange discussion, thank you for reading, hope to help you, thank you for your support of the site!


Related articles: