Q: segfault with if statement I have this code here in C,
When that else statement is there, and i try to print the pointer reference, i get a seg fault. printing the pointer reference in the if(videoPlaying) portion, prints fine, but anywhere outside that, it segfaults.
omxPlayer is defined as FILE *omxPlayer = NULL;
if(videoPlaying == 0)
{
    omxPlayer = popen("omxplayer diehard.mp4", "w");
    printf("%p\n", omxPlayer);
    videoPlaying = 1;
}
else
{
    printf("%p\n", omxPlayer);
}


A: You should check the control flow of your code when videoPlaying != 0 , Most likely You are corrupting memory somewhere in that flow. Just printing out the address of an corrupted pointer should still work fine since it the address is always valid only contents in that address are invalid, so certainly there is something more that is wrong and not seen in the code that you show.           
Your best option is to review the code or run your code under valgrind or any such memory analysis tool and it should point you out what is wrong. 
