Executing from the command line
What you'll learn: How to run your compiled C program by calling its name in the terminal.
After you have written your code and asked the compiler to translate it, you are left with a finished product: the executable file. However, unlike a web browser or a video game on your desktop, a C program usually doesn't have a colorful icon to double-click. In C programming, we stay in the terminal to wake our programs up.
The "Call and Response"
Think of your command line (the terminal) like a waiter at a restaurant. If you want something to happen, you have to call it by its exact name.
When you compiled your code, you likely created a file named a.out (the default name on Linux and macOS) or program.exe (on Windows). To run it, you type that name into the prompt and hit Enter.
On Unix-like systems (Mac/Linux), you add a specific prefix: ./. This tells the computer, "Look right here in this current folder for the program."
// Example: If your program is named "hello"
// You would type this into your terminal:
./hello
// The computer then executes the machine code inside that file.
Why the dot-slash?
You might wonder why you can type ls to list files or gcc to compile, but you have to type ./my_program to run your own code.
This is a safety feature. Your computer has a list of "trusted" folders where it looks for commands. Your personal project folder isn't on that list. By typing ./, you are giving the terminal a direct map to the file, saying: "Don't look in the system folders; look exactly where I am standing right now."
Watching it work
Once you hit Enter, the operating system loads your program into the computer's memory (RAM), and the CPU begins reading the instructions you wrote, starting from the very first line of your main function. When the program finishes its task, it "exits," and the command prompt reappears, waiting for your next instruction.
Key takeaway
To run a compiled C program, type ./ followed by the filename in your terminal and press Enter.