-1

这是 C 代码片段:

 int main()
 {
   char *names=[ "tom", "jerry", "scooby" ];
   printf("%s", *names[0]);// prints t
   printf("%s", *names[1]);// prints j
  // how to print full word "tom", or full word "jerry"
}

如前所述,我希望我的输出是: tom jerry scooby 那么使用指针如何打印整个内容?

4

1 回答 1

3

它编译吗?因为你的数组初始化不正确。要正确声明数组并打印它们,您可以执行以下操作:

#include <stdio.h>

int main(void)
{
   char *names[]= { "tom", "jerry", "scooby" };
   printf("%s %s %s\n", names[0], names[1], names[2]);
   return 0;
}
于 2016-10-14T11:56:13.890 回答