什么是C中"字符数组"的指针?

cal*_*ser 1 c c++ arrays command-line pointers

int check_authentication(char *password) 
  // 1
{
int auth_flag = 0;
char password_buffer[16];

strcpy(password_buffer, password);      // 2
   if(strcmp(password_buffer, "brillig") == 0)
   auth_flag = 1;
   if(strcmp(password_buffer, "outgrabe") == 0)
   auth_flag = 1;
   return auth_flag;
}

check_authentication(argv[1]) // Passing a 'Command Line argument'
// ( which is a string in this example) to the check_authentication function.
Run Code Online (Sandbox Code Playgroud)

我有两个问题.上面标有1和2的行,

  1. 该函数需要一个字符指针作为参数.但是我们传递一个"字符串"i,一个字符数组作为参数.怎么样 ?????

  2. 指针"password"(指向一个字符)所保存的地址被复制到"password_buffer"数组中.对我来说完全是无稽之谈 .请解释一下.

M.M*_*M.M 5

  1. 您正在传递一个指向字符串中第一个字符的字符指针.你实际上没有传递整个字符串.

  2. strcpy函数读取此指针指向的字符,然后继续从下一个内存位置读取连续的字符,直到遇到空终止符.

第一个参数strcpy和两个参数strcmp以相同的方式工作.