#include <iostream>
using namespace std;
struct s
{
int b;
int a;
};
struct s *get_s_ptr(int *a_ptr)
{
cout<< (struct s*)0 << endl;
//cout<< ((struct s*)0)->a << endl; //this will cause an access violation
cout<< &((struct s*)0)->a << endl;
return (struct s*)((char*)a_ptr - (int)&((struct s*)0)->a);
}
int main()
{
struct s s_var;
struct s* s_var_ptr = &s_var;
int *a_ptr = &s_var.a; //pointer to a
s *s_ptr = get_s_ptr(a_ptr); //pointer to s
cout<< "address directly from s pointer: " << s_var_ptr <<endl;
cout<< "address from subroutine: " << s_ptr<< endl;
cin.get();
return 0;
}