To Create a .c file, right-click on the desktop and select a new document and give the name as print.c. Open the file it may be opened in any text editors type the below instructions

  1. #include
  2. int main()
  3. {
  4.    printf(“Execute a sample program\n”);
  5.    printf(“Hello world\n”);
  6.    return 0;
  7. }

The above program is a hello world sample program.

Now save the file. Open the terminal application and change the directory by using the command as follows:
cd /home/Desktop.

now compile the program with GCC tool command as follows:

gcc print.c

if it doesn’t display anything means the program compiled successfully and generated an executable file in the same directory. so to execute a file, command as follows:
./a.out

OUTPUT:
Execute a sample program
Hello world

Like the above strings displayed on the terminal.
Note: while you compile a .c file without flags means by default compiler will generate the executable file with the a.out. If you want to get with a different name means you have to pass -c flag to the compiling instruction.
gcc print.c -c print

Leave a Reply

Your email address will not be published. Required fields are marked *