Execute C program in UNIX

To execute a C program in UNIX , we need a file which have  ‘C’ code in it.In this example we will print “My name is Nitin Srivastava”.Let us first create a C program file named MyName.c:

#include<stdio.h>
main()
{
printf("My Name is Nitin Srivastava");
printf("\n");
}

To compile this C file we will give command cc MyName.c .The output of this command will be a.out file.We can rename this a.out file to something with more relevant name such as PrintName.Use command :
cp a.out PrintName
Now to execute PrintName just give PrintName(or the name to which you’ve renamed a.out file)
The output will be displayed : My Name is Nitin Srivastava

If you know any other method of compiling and executing C code , do share it.Or if you face any issue with this method feel free to comment.

 

Leave a Reply

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