1)给一个单项链表的头,把它反转
struct my_link { int data; struct my_link *next; }; struct my_link *inverselink(struct my_link *inlink) { struct my_link *t; t=inlink; struct my_link *head,*p; head=p=NULL; while(t!=NULL) { p=calloc(sizeof(struct my_link),1); p->data=t->data; p->next=head; head=p; t=t->next; } return head; }
2)const 放在函数的前后面分别有什么区别?
如果是void f(const int a);这种形式的,那么表示a的值在函数中不能被修改, 当然这儿只是个形式,void f(int a);这种方式,a的值也不会被修改。 如果是void f(...) const;这种形式,这一般是类的成员 函数 , 表示这个成员函数不会修改类的成员变量,如果有修改成员变量,那么会编译错误的