Почему вы возвращаете "*" вместо "&", возвращаясь из функции fun?
#include<stdio.h> int &fun() //while int *fun() executes with no problem { static int x = 5; return &x; } int main() { int *p = fun(); fflush(stdin); printf("%d", *p); return 0; }