The above warning implies that you are returning address of a local variable within a function, which you did in your code is the exact reason for the segmentation fault.
int var = 0xff;
return &var; <---------- here
The memory allocated for the local variable in the stack memory gets automatically deleted once the function exits. In your case, the address of variable var is passed to pointer ptr before its exit. Then, you are trying to print the value from the same memory location, which is deleted automatically shortly after the function exits. In short, you are trying to print something which is not there.
You can skip this problem by using the static keyword.
static int var = 0xff;