how to run c program command prompt ?

The C language is designed to create small, fast programs. It’s
lower-level than most other languages.

C is a compiled language. That means the computer will not interpret the code
directly. Instead, you will need to convert—or compile—the human-readable
source code into machine-readable machine code.

 

You start off by creating a source file. The source file contains human-readable C code.

Save the code in a file called  hello.c

hello.c

#include <stdio.h>
int main()
{
puts("C rocks! 5455");
printf("C is the best!");
return 0;
}

Run your source code through a compiler. The compiler checks for errors, and once it’s happy, it compiles the source code.

Compile with gcc hello.c -o  hello at a command prompt or terminal.

gcc hello.c -o hello

The compiler creates a new file called an executable. This file contains machine code, a stream of 1s and 0s that the computer understands. And that’s the program you can run.

By using ls command you can see an Executable  file called hello

 

Run by typing   ./hello on Mac and Linux machines.

./hello
C rocks! 5455
C is the best!

 

Leave a Reply