gpt4 book ai didi

c - 在函数中声明指针语法

转载 作者:太空狗 更新时间:2023-10-29 17:21:40 25 4
gpt4 key购买 nike

两个指针语句是否相同?

void reverse(const char * const sPtr){


}

void reverse(const char const *sPtr){


}

最佳答案

没有。

const char const *sPtr 等同于const char *sPtr.

const char *sPtr 说参数 sPtr 是指向 const char 的指针。

const char * const sPtr 是指向 const charconst 指针。

请注意,这在 C99 和 C11 中是等效的:

(C99, 6.7.3p4) "If the same qualifier appears more than once in the same specifier-qualifier-list, either directly or via one or more typedefs, the behavior is the same as if it appeared only once."

但在 C89 中不是,其中 const char const *sPtr 是约束违规:

(C90, 6.5.3) "The same type qualifier shall not appear more than once in the same specifier list or qualifier list, either directly or via one or more typedefs."

关于c - 在函数中声明指针语法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8916314/

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