Home  >  Article  >  php教程  >  The difference between string pointer and character array

The difference between string pointer and character array

高洛峰
高洛峰Original
2016-12-12 17:22:231922browse

Character arrays and character pointer variables can be used to store and operate strings. But there is a difference between the two. You should pay attention to the following issues when using it:

1. The string pointer variable itself is a variable used to store the first address of the string. The string itself is stored in a continuous memory space headed by the first address and ends with ‘

View Code  
  #include  
 #include  
    
   /******************************************************************************/  
  /* 
   *    Convert a string to lower case 
   */  
    
  int strlower(char *string)  
 {  
     if(string==NULL)  
     {  
         return -1;  
     }  
   
     while(*string)  
     {  
         if(isupper(*string))  
             *string=tolower(*string);  
         string++;  
     }  
     *string='\0';  
     return 0;  
 }  
 /*char *strlower(char *string) 
 { 
     char    *s; 
  
      
  
     if (string == NULL) { 
         return NULL; 
     } 
  
     s = string; 
     while (*s) { 
         if (isupper(*s)) { 
             *s = (char) tolower(*s); 
         } 
         s++; 
     } 
     *s = '\0'; 
     return string; 
 } 
 */  
   
 void main()  
 {  
     char *test="ABCDEFGhijklmN";  
     strlower(test);  
     cout<

其中,如果采用char *test=”ABCDEFGhijklmN”;会产生运行时错误。Char test[]=”ABCDEFGhijklmN”则程序正常运行,原因如前所述。

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn