【发布时间】:2016-02-12 21:53:35
【问题描述】:
这是我写的程序:
main()
{
struct book
{
char name[25] ;
char author[25] ;
int callno ;
} ;
struct book b1 = { "Let us C", "YPK", 101 };
display(b1.name, b1.author, b1.callno);
}
void display(char *s, char *t, int n)
{
printf ("\n%s %s %d", s, t, n);
}
输出是
让我们 C YPK 101
根据需要
现在我们传递给函数display() 的是字符串name 和author 的基地址,并且在函数的定义中使用指针。那么为什么函数像printf("\n%s %s %d", s, t, n) 而不是printf("\n%s %s %d", *s, *t, n)?
第二个没有运行。 s 不是基地址,*s 不是存储在该地址的字符串吗?
【问题讨论】:
-
main()应该是int main(void),并且您需要在顶部使用#include <stdio.h>。