I have below code and It gives an error as "segmentation fault" in some compiler but for other compilers it gives "40" as output. Why is there difference?
#include <stdio.h>
class A{
int *ptr;
public:
void set(int val) const;
};
void A::set(int val) const{
*ptr = val;
printf("%d", *ptr);
}
int main(){
A a;
a.set(40);
return 0;
}