Run your first C program

Lets see compile and run a program on Linux platform.

1. Create a file named myprogram.c and write the following.

#include <stdio.h>

int main (void)

{

printf (“This is my first program.\n”);

return 0;

}

2. Save the file. In the command prompt, type

gcc -c myprogram.c

A new file named myprogram.o will be created in the same directory. This is the object file.

3. lets create the executable file for source code. Type

gcc -omyprogram myprogram.o

An executable named myprogram will be created.

4. To run the program, type

./myprogram

“This is my first program.” will be displayed on the terminal.

 

If you did not see any error, then your first program has been successfully executed. Congratulations!

 

You may also like...

Leave a Reply

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