0

I have a question here and do not understand why I can't print the memory address of my function pointer. Can anyone explain why? Thanks!

#include <stdio.h>
#include <iostream>

void displayFourIncrementVar(int &x)
{
    printf( "%d\n", 4 );
    x++;
}

int main()
{
    int y = 4;
    int *z = &y;
    std::cout << *z << std::endl;
    std::cout << z << std::endl << std::endl;
    //printing out z we have an address.  

    void (*garbage)(int&) = &displayFourIncrementVar;
    std::cout << garbage << std::endl << std::endl;
    //Printing out garbage we have no address, instead we get 1, why's that?
    //I thought pointers store memory addresses in dexadecimal.

    int x = 2;
    (*garbage)(x);
    std::cout << x << std::endl; 
    return 0;
}
Fortunata
  • 37
  • 7

0 Answers0