This segment calls func3 with argument *p
and since p being a null pointer this program should have crashed at function call.
#include <iostream>
using namespace std;
void func3(int &a)
{
cout<<"Not Crashing?\n";
}
int main()
{
int *p = NULL;
func3(*p);
return 0;
}
I thought compiler is not resolving *p
in case of pass by reference, just making an alias to it, somehow. So, I tried the following code segment:
#include <iostream>
using namespace std;
void func3(int *a)
{
cout<<"Not Crashing?\n";
}
int main()
{
int *p = NULL;
func3(&(*p)); // &(*p) == p
return 0;
}
In func3(&(*p))
, I'm de-referencing a null pointer and then referencing it again. But it still won't crash.