​​​​​​​​​​C tutorials #6

Compile & Execute

Let us see how to save the source code in a file, and how to compile and run it.
For Turbo C++ compiler Users
Following are the simple steps −
Step 1: Locate the TC.exe file and open it. You will find it at location C:\TC\BIN\.
Step 2: File > New (as shown in above picture) and then write your C program
#include<stdio.h> 
int main()
{
  printf("hello World!");
  return 0;
}

Step 3: Save the program using F2 (OR file > Save), remember the extension should be “.c”. In the below screenshot I have given the name as helloworld.c.
Step 4: Compile the program using Alt + F9 OR Compile > Compile
Step 5: Press Ctrl + F9 to Run (or select Run > Run in menu bar ) the  C program.
Step 6: Alt+F5 to view the output of the program at the output screen.
For gcc compiler Users
Source code Helloworld.c (file should always be saved with .c extension)
Type the above code on your compiler
Compile it (it is basically converting a helloworld.c file to a helloworld file)
>gcc helloworld.c –o helloworld >
The generated file would be helloworld.exe if you are compiling on windows.
Run the compiled program
Once you give the above command, a .exe file would have been created if you are on windows then type the following command to run the source code.
For Windows
>helloworld
For Mac and Linux OS
>./helloworld
gcc compiler takes the human readable format (helloworld.c file) and converted into a machine code for Windows, Linux and Mac OS X.

Comments