Undefined var still prints

how can this code work?
how can it print num1 in main function when num1 has not been defined as a var by me???

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

using namespace std;

int num1()
{
    int var1 = 4;
    cout<< 4 << endl;
    return 0;
}
int main(int argc, char *argv[])
{
    num1();
    cout<<num1;
    system("PAUSE");
    return 0;
}
you're printing out the location in memory of your function num1().
Yes, indeed num1 was defined by you.

num1 was defined by you in line 6.

In line 15 num1 is the address of the function you defined in line 6

http://stackoverflow.com/questions/840501/how-do-function-pointers-in-c-work
Topic archived. No new replies allowed.