silinos silinos - 14 days ago 5
C Question

I need to pass the arguments of function1 to another function2 inside function1

To be more specific, the code is like this

main(){

int a; int b; func(&a,&b); }

void func(int *x,int *y){

func1(...); }/*i need to pass x,y in func1*/

void func1(int ,int ){ ... }


The arguments x,y came from my main and i dont know how to pass them to func1, in order to modify them in the scope of this function

Answer

You simply pass them on, but in order for func1 to be able to modify and pass them back you must change func1 to accept pointers.

Your prototype for func1 must be changed to:

    void func1(int* a, int* b);

Then:

    void func(int *x,int *y) {
        func1(x, y);
    }