我是 C 和指针的新手,我想知道是否可以将数组指针传递给函数,而不是传递字符数组本身。我正在发布代码片段。
char ipAddress[24];
int i, j;
for (i = 12; i <= 13; i++)
{
for (j = 1; j <= 254; j++)
{
sprintf(ipAddress,"192.168.%d.%d",i,j);
runCommand(ipAddress);
}
}
// ...
int runCommand (char x[24])
{
// Do stuff.
}
最佳答案
C 中数组总是通过指针传递,而不是通过值传递(复制)
所以
int runCommand (char x[24]);
与
非常接近int runCommand (char *x);
关于C 通过指针将数组传递给函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19662694/