In another way, the code (int *)&l says that referring to a pointer as a pointer to an int. It does not convert anything. So (int *) tells the compiler to let you pass a long * to a function waiting for int *. You lie to him. Internally, foo expects x to be a pointer to an int, but that is not the case. The memory layout is not what it should be. The results, as you see, are unpredictable.
In another note, I would never use l (ell) as a variable name. It is too easy to confuse with 1 (one). For example, what is it?
int x = l;
source share