标题:【求助】形参与实参的传值和传址问题!
取消只看楼主
S140131022
Rank: 2
来 自:重庆邮电大学
等 级:论坛游民
帖 子:205
专家分:35
注 册:2014-10-9
结帖率:90.24%
已结贴  问题点数:20 回复次数:2 
【求助】形参与实参的传值和传址问题!
#include<stdio.h>
#include<string.h>

int main()
{
    void print(char *p[],int n);
    void convert(char *p[],int n);
    char *p[]={"Follow me","BASIC","Great Wall","FORTRAN","Computer design"};
    puts("________The Origin following is:________\n");
    print(p,5);
    convert(p,5);
    puts("________The Turned following is:________\n");
    print(p,5);
    return 0;
}

void print(char *p[],int n)
{
    int i;
    for(i=0;i<n;i++)
    {
        puts(p[i]);
        putchar('\n');
    }
}

void convert(char *p[],int n)   //指向指针的数组。。。
{
    int i,j;
    char x[100];
    char *q;
    q=x;
    for(i=0;i<n-1;i++)
    {
        for(j=0;j<n-1-i;j++)
        {
            if(strcmp(p[j],p[j+1])>0)
            {

                q=p[j];
                p[j]=p[j+1];
                p[j+1]=q;                          //我感觉此处相当于给形参数据回传给了实参。。。
            }
        }
    }
}

//为什么这个字符串排序的程序可以正确排序。我感觉这个函数是值传递而非地址传递~~  应该形参的排序应该无法影响形参才对。但是它确实起作用了,请解释一下哦!
搜索更多相关主题的帖子: 网店 return include convert following 
2015-04-07 20:47
S140131022
Rank: 2
来 自:重庆邮电大学
等 级:论坛游民
帖 子:205
专家分:35
注 册:2014-10-9
得分:0 

既然还有不甘心
就还没到放弃的时候~
2015-04-07 20:52
S140131022
Rank: 2
来 自:重庆邮电大学
等 级:论坛游民
帖 子:205
专家分:35
注 册:2014-10-9
得分:0 
回复 3楼 longwu9t
thank you !

既然还有不甘心
就还没到放弃的时候~
2015-04-08 14:46



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-443672-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 1.010413 second(s), 8 queries.
Copyright©2004-2025, BCCN.NET, All Rights Reserved