0
Follow
0
View

If you want to calculate the length of a char array, you must use double quotation marks

dongsx1989 注册会员
2023-02-27 21:27

This answer quotes ChatGPT

In C++, the single quotation mark "" is often used to indicate character constants, such as 'a' for the character a. Therefore, it is illegal to use single quotes to assign an array because an array should contain multiple elements rather than a single character.

Normally, to initialize an array, use braces {} to contain a list of elements, such as

int arr[] = {1, 2, 3, 4, 5};

This creates an integer array arr with five elements, where each element is 1, 2, 3, 4, and 5.

Of course, you can also use loop statements to assign values to arrays, such as .
int arr[5];
for (int i = 0; i < 5; i++) {
    arr[i] = i + 1;
}

This also creates an integer array arr with five elements, where each element is 1, 2, 3, 4, and 5.

About the Author

Question Info

Publish Time
2023-02-27 21:27
Update Time
2023-02-27 21:27

Related Question

微信小程序可以通过WIFI来传输字符串数据吗

仅为现有用户运行代码- SwiftUI/iOS/Swift

UnsatisfiableError: The following specifications were found to be?

ExifInterface接口setAttribute()设置ExposureTime丢失精度

为什么“if”改变了这个变量的作用域

Laravel 9可以使用vite.config.js显示libnotify-bin通知吗?

C语言里else if

matlab使用for、if嵌套,为什么没有触发if判断

颤振[Android]有办法打开/关闭WIFI吗?

在while循环和if条件中追加一个数组