Pointer function to main

How do you call the pointer function back to main? I already try "&" didnt work.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
For example: I have prototype 

void example (int, int, *int,*int,*int,*int);
int main
{
      ............
     example (int, int, &int,&int,&int,&int); // didnt work.
}
void example (int, int, *int,*int,*int,*int);
{

    putting code here!
}
Last edited on
You wouldn't pass data types. You'd pass actual arguments.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
#include <iostream>

void exampleFunction( int foo, int *p_foo );

int main( int argc, const char *argv[] )
{
    int a = 0;

    exampleFunction( a, &a );

    return 0;   
}

void exampleFunction( int foo, int *p_foo )
{
    std::cout << "Function called\n";
}
as i say it didnt work
What do you mean by call pointer function back to main? When function execution ends, it goes back to the place it got called, and in this case - it would be main function.

PS. "Pointer function"(which I would define, basing on your words, as a function that takes some pointer types as arguments) is not different from "normal" function.
Last edited on
because it returns an int, you haveto store it in a variable.
int ex = example(//parameters....);
in pointer function I have it to find a smallest number now I need to get that information back to main so i can cout in main not in the function
sorry it a void function!
Then you need to pass by reference.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
#include <iostream>

void exampleFunction( int &foo );

int main( int argc, const char *argv[] )
{
    int a = 0;

    exampleFunction( a );

    std::cout << "a is now: " << a << std::endl;

    return 0;   
}

void exampleFunction( int &foo )
{
    foo = 10;
}
Topic archived. No new replies allowed.