C++ Fibonacci number example

How to Run C++ Program on Mac Terminal

  • C++
  • 1 min read

Use g++ command to compile a C++ program and build the executable so that you can run the C++ program on the Mac terminal. Below is the syntax of g++ command:

g++ Syntax

g++ programname.cpp -o executablename


Suppose you have written a C++ program in a file named hellow.cpp. Then open the terminal window change the directory to the file location and execute the following g++ command:

g++ hellow.cpp -o hellow

The above first command will compile the hellow.cpp and build the executable hellow. The command in the second line above will run the C++ program hellow.

Related Tutorials:

Fibonacci Series in C++ (Recursion Example)