函数中的const是什么意思呢?


#include 
#include <string.h>

int GetWords(char *sentence, char *words[]);
void SortStrings(const char *strs[], int count);

int main()
{
    char str[200];
    int nWords = 0;
    char *words[20];
    int i;
    
    printf("input a string: ");
    gets(str);
    
    nWords = GetWords(str, words);
    SortStrings(words, nWords);
    
    puts("output:");
    for(i=0; i[i]);
    
    return 0;
}


int GetWords(char *str, char *words[])
{
    /******start******/
    int cnt=1;
    words[0]=&str[0];
    for(int i=0;iif(str[i]==' ') {
            cnt++;
            words[i]=&str[i+1];
            str[i]='\0';
        }
    }
    return cnt;
    /******end******/
}

void SortStrings(const char *strs[], int count)
{
    /******start******/
    
    /******end******/
}

const 只读的,一般是指常量,常数,不能修改的字符串等。

const限定符,是告诉编译器被const限定的变量的值是不可修改的。const限定符常用来,防止被调用函数修改主调函数的对象