Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
220 views
in Technique[技术] by (71.8m points)

c++ - what does undefined reference to a recursive function mean?


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

You can't define reverse inside of main like that. Move it out separate from main, something on this general order:

#include <stdio.h>
#include <string.h>
#include <math.h>
#include <stdlib.h>

int reverse(int o,int k,int* p){ 
    
    temp = *(p+k);
    *(p+k)=*(p+o);
    *(p+o) = temp;
    o=o-1;k=k+1;
    
    if(o==k)
    {
        return 0;
    }
    else if((k+1)==o){
        temp = *(p+k);
        *(p+k)=*(p+o);
        *(p+o) = temp;
        return 0;
    }
    else{
        reverse(o,k,p);
    }
}

int main() {
    int temp,n,i;

    scanf("%d",&n);
    int a[n];

    for(i=0;i<n;i++)
        scanf("%d",&a[i]);

    int y = reverse(n,(int)0,&a[0]);

    for(i=0;i<n;i++)
        printf("%d",a[i]);

    return 0;
}

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...