字符数组赋值
例如:
main()
{
char s[100];
strcpy(s, "The writer would like to thank you for"
"your interest in his book. He hopes you"
"can get some helps from the book.");
}
指针数组赋值
例如:
main()
{
char *f[2];
int *a[2];
f[0]="thank you"; /*给字符型数组指针变量赋值*/
f[1]="Good Morning";
*a[0]=1, *a[1]=-11; /*给整型数数组指针变量赋值*/
}
1、定义的时候直接用字符串赋值
char a[10]="hello";
注意:不能先定义再给它赋值,如char a[10]; a[10]="hello";这样是错误的!
2、对数组中字符逐个赋值
char a[10]={'h','e','l','l','o'};
3、利用strcpy
char a[10]; strcpy(a, "hello");