可能的重复:
为什么 sizeof(param_array) 是指针的大小? https://stackoverflow.com/questions/11622146/why-sizeofparam-array-is-the-size-of-pointer
我是 C 新手,我收到了警告clang
编译我的代码时:
#include<stdio.h>
char *strcpy (char destination[],const char source[]);
int main(void) {
char str1[] = "this is a very long string";
char str2[] = "this is a short string";
strcpy(str2, str1);
puts(str2);
return 0;
}
char *strcpy (char destination[], const char source[]) {
int size_of_array = sizeof source / sizeof source[0];
for (int i = 0; i < size_of_array; i++) {
destination[i] = source[i];
}
return destination;
}
我不知道以下警告是什么意思:
string_copy_withou_pointer.c:12:29: warning: sizeof on array function parameter
will return size of 'const char *' instead of 'const char []'
[-Wsizeof-array-argument]
int size_of_array = sizeof source / sizeof source[0];
^
string_copy_withou_pointer.c:11:46: note: declared here
char *strcpy (char destination[], const char source[]) {
任何想法?
此警告告诉您,如果您致电sizeof(char[])
你不会得到数组的大小,而是得到a的大小char*
指针。
这意味着你的变量size_of_array
将是错误的,因为它不代表真实数组的大小。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)