链表,形参,实参
在学习C语言的时候,关于形参如何改变实参,链表中节点的值何时被改变,何时不被改变,一直没有搞明白,今天终于搞懂,记录下来备份。1、形参改变实参
<div style="padding-right: 5.4pt; padding-left: 5.4pt; background: #e6e6e6; padding-bottom: 4px; width: 95%; padding-top: 4px;">http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif#include <stdio.h>
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif#include <malloc.h>
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.giftypedef struct LNode
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockStart.gifhttp://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedBlock.gif...{
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif FILE *fp;
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif char *fname;
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif struct LNode *next;
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockEnd.gif}LNode;
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gifLNode *LinkList;
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockStart.gifhttp://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedBlock.gifLNode *ListInit(LNode *linklist)...{
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gifhttp://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif if((linklist=(LNode *)malloc(sizeof(LNode)))==NULL)...{
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif printf("Init Link Error");
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif exit(0);
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif }
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif linklist->next=NULL;
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif return linklist;
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockEnd.gif}
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockStart.gifhttp://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedBlock.gifListInsert(LNode *linklist, char *fname,FILE *fp)...{
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif LNode *lnode;
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif LNode *p;
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif p=linklist;
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gifhttp://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif if((lnode=(LNode*)malloc(sizeof(LNode)))==NULL)...{
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif printf("Insert Error");
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif exit(0);
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif }
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gifhttp://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif while(p->next!=NULL)...{
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif p=p->next;
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif if(!strcmp(p->fname,fname))
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gifhttp://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif ...{
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif p->fp=fp;
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif return ;
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif }
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif }
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif p->next=lnode;
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif lnode->fp=fp;
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif lnode->fname=fname;
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif lnode->next=NULL;
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif p=lnode;
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif //注意这一段代码,这里只是改变了test指针指向的所指变量的值,即fname的值,
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif //故,在main函数中的fname的值会发生变化
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gifhttp://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif while(*fname!='
页:
[1]