gpt4 book ai didi

c - 初始化char数组的不同方式

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

用大括号和不带大括号初始化 char 数组有什么区别?

char arr[] = {"string"};

char arr[] = "string";

最佳答案

没有区别。 C99 直接解决了这个问题,6.7.8 初始化:

  1. An array of character type may be initialized by a character string literal, optionally enclosed in braces. Successive characters of the character string literal (including the terminating null character if there is room or if the array is of unknown size) initialize the elements of the array.

(强调我的。)

关于c - 初始化char数组的不同方式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52232560/

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