Is it true that most of the times source code for Linux programs can be compiled into Mac OS programs and vice versa?
The world of source code is so large that "most" is a hopelessly vague qualifier.
Programs written in "scripting" languages like Ruby, Perl, or Python, usually run on both OS X and Linux with no or minor modifications.
Compiled command line programs depending only on the C or C++ standard libraries can usually be ported with little difficulty. However, since Apple has dropped support for GCC in favor of Clang, even this can't be absolutely depended on. GCC and Clang may behave differently in the case of undefined behavior in the C or C++ spec.
Programs that use explicit system calls or a GUI, may be quite difficult to port and may have to be re-written entirely.