How to compile and execute a c program in linux
Question: How to compile and run c program in linux operating system
Answer: To compile a c program use “gcc command” and to run a c program use “./” .
In this post i am going to explain you how to compile and run c program in linux operating system. If you are a programmer and working on Linux / Unix like operating system you should aware of how to compile and execute c program in linux / Unix operating system. Lets see how to accomplish the task with an example
In my scenario i am creating a basic “Hello World” c program with file name helloworld.c
To compile C program helloworld
If their is any error in the program it will tells you while compile itself
Before executing a c program make it as an binary executable file using below command.
#gcc helloworld.c -o helloworld
How to verify a file is a binary file or not
helloworld: ELF 32-bit LSB executable, Intel 80386, version 1 (SYSV), for GNU/Linux 2.6.9, dynamically linked (uses shared libs), for GNU/Linux 2.6.9, not stripped
Once the c program is complied and changed in to binary file execute or run it using below command