小问题..C++..看下下

来源:百度知道 编辑:UC知道 时间:2024/06/08 06:25:07
char b[4]={hunter,wolf,sheep,cabbage};

这样写不可以么...那要怎么样写啊
为什么不能这样写..
我就是想定义一个数组...然后其初始化呀...

不可以,应该这样:
char *b[4]={"hunter","wolf","sheep","cabbage"};

利用如下程序可以验证:
#include <stdio.h>
void main()
{
char *b[4]={"hunter","wolf","sheep","cabbage"};
}
编译、运行完全正确。

char *b[4]={hunter,wolf,sheep,cabbage};

string b[4]={hunter,wolf,sheep,cabbage};

char *b[4]={"hunter","wolf","sheep","cabbage"};