【发布时间】:2011-12-22 14:34:04
【问题描述】:
我对以下 C 程序中 %c 和 %s 的使用感到困惑
#include <stdio.h>
void main()
{
char name[]="siva";
printf("%s\n",name);
printf("%c\n",*name);
}
输出是
siva
s
为什么我们需要使用指针来显示字符%c,而字符串不需要指针
我在使用时遇到错误
printf("%c\n", name);
我得到的错误是
str.c: In function ‘main’:
str.c:9:2: warning: format ‘%c’ expects type ‘int’, but argument 2 has type ‘char *’
【问题讨论】: