我是一只小小鸟 发表于 2018-12-25 19:54:40

c语言中函数初学者的问题

本帖最后由 我是一只小小鸟 于 2018-12-25 20:39 编辑

本函数实现对主函数中数组数据进行从小到大排序得功能。
#include <stdio.h>
voidpupple (int a[],int n );
int main()
{
int a[]={3,2,1,0,9,8,7,4,5,6};
int i,n;
        scanf("%d",&n);
pupple(a,n);
        for(i=0;i<n;i++)
      printf("%d ", a );
return 0;
}
voidpupple (int a[],int n )
{
        int j,k;
        for(j=0;j<n-1;j++)
        {
                if(a>a)
                {
                        k=a;
                        a=a;
                        a=k;
                }
        }
}
我应该怎么返回值呀?

我是一只小小鸟 发表于 2018-12-25 19:59:45

{:10_257:}快来大佬呀!

winktv2002 发表于 2018-12-25 21:06:52

什么返回值?
2个函数,一个是main函数,一个是pupple函数,2个函数的数据大部分是存在栈中的,用完了指针就不再指向了。


0804846d <main>:
804846d:        55                           push   ebp
804846e:        89 e5                        mov    ebp,esp
8048470:        83 e4 f0                     and    esp,0xfffffff0
8048473:        83 ec 40                     sub    esp,0x40
8048476:        c7 44 24 18 03 00 00         mov    DWORD PTR ,0x3
804847d:        00
804847e:        c7 44 24 1c 02 00 00         mov    DWORD PTR ,0x2
8048485:        00
8048486:        c7 44 24 20 01 00 00         mov    DWORD PTR ,0x1
804848d:        00
804848e:        c7 44 24 24 00 00 00         mov    DWORD PTR ,0x0
8048495:        00
8048496:        c7 44 24 28 09 00 00         mov    DWORD PTR ,0x9
804849d:        00
804849e:        c7 44 24 2c 08 00 00         mov    DWORD PTR ,0x8
80484a5:        00
80484a6:        c7 44 24 30 07 00 00         mov    DWORD PTR ,0x7
80484ad:        00
80484ae:        c7 44 24 34 04 00 00         mov    DWORD PTR ,0x4
80484b5:        00
80484b6:        c7 44 24 38 05 00 00         mov    DWORD PTR ,0x5
80484bd:        00
80484be:        c7 44 24 3c 06 00 00         mov    DWORD PTR ,0x6
80484c5:        00
80484c6:        8d 44 24 10                  lea    eax,
80484ca:        89 44 24 04                  mov    DWORD PTR ,eax
80484ce:        c7 04 24 60 86 04 08         mov    DWORD PTR ,0x8048660
80484d5:        e8 86 fe ff ff               call   8048360 <__isoc99_scanf@plt>
80484da:        8b 44 24 10                  mov    eax,DWORD PTR
80484de:        89 44 24 04                  mov    DWORD PTR ,eax
80484e2:        8d 44 24 18                  lea    eax,
80484e6:        89 04 24                     mov    DWORD PTR ,eax
80484e9:        e8 38 00 00 00               call   8048526 <pupple>
80484ee:        c7 44 24 14 00 00 00         mov    DWORD PTR ,0x0
80484f5:        00
80484f6:        eb 1d                        jmp    8048515 <main+0xa8>
80484f8:        8b 44 24 14                  mov    eax,DWORD PTR
80484fc:        8b 44 84 18                  mov    eax,DWORD PTR
8048500:        89 44 24 04                  mov    DWORD PTR ,eax
8048504:        c7 04 24 63 86 04 08         mov    DWORD PTR ,0x8048663
804850b:        e8 20 fe ff ff               call   8048330 <printf@plt>
8048510:        83 44 24 14 01               add    DWORD PTR ,0x1
8048515:        8b 44 24 10                  mov    eax,DWORD PTR
8048519:        39 44 24 14                  cmp    DWORD PTR ,eax
804851d:        7c d9                        jl   80484f8 <main+0x8b>
804851f:        b8 00 00 00 00               mov    eax,0x0
8048524:        c9                           leave
8048525:        c3                           ret   

08048526 <pupple>:
8048526:        55                           push   ebp
8048527:        89 e5                        mov    ebp,esp
8048529:        83 ec 10                     sub    esp,0x10
804852c:        c7 45 f8 00 00 00 00         mov    DWORD PTR ,0x0
8048533:        eb 7d                        jmp    80485b2 <pupple+0x8c>
8048535:        8b 45 f8                     mov    eax,DWORD PTR
8048538:        8d 14 85 00 00 00 00         lea    edx,
804853f:        8b 45 08                     mov    eax,DWORD PTR
8048542:        01 d0                        add    eax,edx
8048544:        8b 10                        mov    edx,DWORD PTR
8048546:        8b 45 f8                     mov    eax,DWORD PTR
8048549:        83 c0 01                     add    eax,0x1
804854c:        8d 0c 85 00 00 00 00         lea    ecx,
8048553:        8b 45 08                     mov    eax,DWORD PTR
8048556:        01 c8                        add    eax,ecx
8048558:        8b 00                        mov    eax,DWORD PTR
804855a:        39 c2                        cmp    edx,eax
804855c:        7e 50                        jle    80485ae <pupple+0x88>
804855e:        8b 45 f8                     mov    eax,DWORD PTR
8048561:        8d 14 85 00 00 00 00         lea    edx,
8048568:        8b 45 08                     mov    eax,DWORD PTR
804856b:        01 d0                        add    eax,edx
804856d:        8b 00                        mov    eax,DWORD PTR
804856f:        89 45 fc                     mov    DWORD PTR ,eax
8048572:        8b 45 f8                     mov    eax,DWORD PTR
8048575:        8d 14 85 00 00 00 00         lea    edx,
804857c:        8b 45 08                     mov    eax,DWORD PTR
804857f:        01 c2                        add    edx,eax
8048581:        8b 45 f8                     mov    eax,DWORD PTR
8048584:        83 c0 01                     add    eax,0x1
8048587:        8d 0c 85 00 00 00 00         lea    ecx,
804858e:        8b 45 08                     mov    eax,DWORD PTR
8048591:        01 c8                        add    eax,ecx
8048593:        8b 00                        mov    eax,DWORD PTR
8048595:        89 02                        mov    DWORD PTR ,eax
8048597:        8b 45 f8                     mov    eax,DWORD PTR
804859a:        83 c0 01                     add    eax,0x1
804859d:        8d 14 85 00 00 00 00         lea    edx,
80485a4:        8b 45 08                     mov    eax,DWORD PTR
80485a7:        01 c2                        add    edx,eax
80485a9:        8b 45 fc                     mov    eax,DWORD PTR
80485ac:        89 02                        mov    DWORD PTR ,eax
80485ae:        83 45 f8 01                  add    DWORD PTR ,0x1
80485b2:        8b 45 0c                     mov    eax,DWORD PTR
80485b5:        83 e8 01                     sub    eax,0x1
80485b8:        3b 45 f8                     cmp    eax,DWORD PTR
80485bb:        0f 8f 74 ff ff ff            jg   8048535 <pupple+0xf>
80485c1:        c9                           leave
80485c2:        c3                           ret   
80485c3:        66 90                        xchg   ax,ax
80485c5:        66 90                        xchg   ax,ax
80485c7:        66 90                        xchg   ax,ax
80485c9:        66 90                        xchg   ax,ax
80485cb:        66 90                        xchg   ax,ax
80485cd:        66 90                        xchg   ax,ax
80485cf:        90                           nop
页: [1]
查看完整版本: c语言中函数初学者的问题