g++ compiler error

I am compiling a .c file with the command:
g++ main.c -o main
The command is successful and the executable is made. However sometimes the executable does not work while others with the same code the executable is successful. Has anyone else had a problem similar?

Did you try compiling with gcc?
g++ => main.cc, main.cpp
gcc => main.c

Chad Baker
Professor Emeritus
Christian Brothers University
Electrical and Computer Engineering
650 East Parkway South
Memphis, TN 38104