gpt4 book ai didi

c - 我收到此警告 : sizeof on array function parameter will return size of 'const char *' instead of 'const char []'

转载 作者:太空宇宙 更新时间:2023-11-04 00:15:29 24 4
gpt4 key购买 nike

<分区>

Possible Duplicate:
Why sizeof(param_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[]) {

有什么想法吗?

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com