C语言的几道题目不懂。感觉蛮复杂的。C高手进啊。谢谢~

#include "stdio.h"
int a;
int m(int a)
{static int s; return (++s)+(--a);}
void main()
{int a=2;printf("%d",m(m(a)));}
这道题目的答案是3 可是我做不出来。

求以下程序输出结果的第一行 第二行。
#include "stdio.h"
void main()
{ int i=5;
do
{ switch(i%2)
{ case 0:i--;break;
case 1:i--;continue;
}
i--;printf("%d\n",i);
}while(i>0);
}
答案是2,0.
难道switch语句也有循环功能?

求输出结果的第一行 第二行 第三行
struct node
{char data;struct node *next;};

struct node *insert(struct node *h,char c)
{struct node *p,*p1,*p2;
p=(struct node*)malloc(sizeof(struct node));p->data=c;p->next=NULL;
if(h==NULL) h=p;
else
{p1=p2=h;
while(c>p1->data&p1->next!=NULL)
{p2=p1;p1=p1->next;}
if(c<=p1->data)
if(p1==h) {p->next=h;h=p;}
else {p1->next=p;p->next=p1;}
else {p1->next=p;}
}
return h;
}

struct node *del(struct node *h)
{struct node *p=h;
while(p!=NULL)
{if(p->data%2==0) p->next=p->next->next;
p=p->next;

}
return h;
}

void print (struct node *h)
{struct node *p=h;
while(p!=NULL)
{printf("%c",p->data);p=p->next;}
printf("\n");

}

void main()
{struct node *head=NULL;char *item="32659",*p=item;
puts(item);
while(*p)head=insert(head,*p++);
print(head);del(head);print(head);
}
答案是32659,23569,256
哪位大虾可以解释一下链表的函数是怎么个调用法的。如果嫌麻烦就用struct node *del(struct node *h)
这一段为例。

一下程序中有语法错误的是()
A fun(char aa[10])
{ while (*aa) printf("%c",*aa++);}
B fun(char *aa)
{ while (aa[0]) printf("%c",*aa++);}
C main()
{char *aa="hello!";}
{while (*aa) printf("%c",*aa++);}
D main()
{char aa[10]="hello!";}
{while (*aa) printf("%c",*aa++);}
答案是D请给出错误的原因。

另外是一些小的问题:
1,root(0)是什么作用啊 。
2。指针*P,与a[10],&a[10]的关系。这里的a[10]只是举的一个例子。
第三题的第十三行的p1应改为p2

1
局部静态变量的值,会默认初始化为0.而且在下一次再进行函数时,仍保留上次结束时的值.
所以第一次执行时,s=0,++s+(--a)=1+1=2,第二次时,s=1, ++s+(--a)=3

2
这里的break;是跳出switch,continue则是继续do-while循环.
所以开始i=5,%2=1,i--得到4,然后continue继续循环,4%2=0,执行i--,得到3,退出switch,执行 i--;printf("%d\n",i);打印出2.
再继续循环,2%2=0,i--得到1,退出swtich,再是 i--;printf("%d\n",i);打印出0

3
链表类的程序你最好自己在纸上画示意图,这种东西没法用文字解释.

4.
char aa[10]如果写在函数参数声明里的话,这个10实际上是被编译器忽略掉,编译器只会把数组参数看成指针.
而如果你写在函数体中的话,char aa[10]就真的是个数组了,而数组名是常量,是不允许修改的,所以*aa++会导致对常量进行写操作的错误

root(0)就是root=0;
温馨提示:答案为网友推荐,仅供参考
第1个回答  2009-07-15
沙发没了。。。~
我比你更绝望。。。我没用编译器的情况下算的结果:
第一题 s没赋初值,难道static int s有赋初值的功能?(被我猜中了)
第二题 我算得的结果是3,1,-1。。。。。(被continue戏耍了)
第三题 链表的函数我正在学。。。。。。(大哥您就将就着表达一下吧)
同求答案中。。。。。
谢谢楼上辛苦解答
相似回答
大家正在搜