Site icon TestingDocs.com

Getting Started with the First C Program

Overview

Let us see how to write a basic first C program that says “Hello, world!” on the console using CodeBlocks IDE on Windows. You need an editor to code your program. Editors like Notepad++, TextPad, etc, and for serious programming consider using IDE’s like Eclipse, CodeBlocks, etc. If you use a text editor you need to perform most of the tasks manually.

Create a New Project

Add a new C file and save the source file as “hello.c”. A C source file should be saved with a file extension of “.c”. A Thumb rule, you should choose a filename that reflects the purpose of the program.

C program

/*

* C program to say Hello World!

*/

// Standard header file to perform I/O operations

#include <stdio.h> // preprocessor directive

// main function . The program entry point. 
int main() { printf("*****************\n"); // Prints *'s printf("Hello World!\n"); // Prints Hello World! printf("*****************\n"); return 0; // terminate the main() function } // End of main() function

 

Build the Project

Executable Code: Compile and build the source code “hello.c” into executable code in Windows To build the project Hit the Build menu option (Ctrl -F9)  

 

 

————–

Build: Debug in SampleProject (compiler: GNU GCC Compiler)————— i686-w64-mingw32-gcc.exe -Wall -g -march=i586 -c C:\CODEBLOCKS64\SampleProject\hello.c -o obj\Debug\hello.o i686-w64-mingw32-g++.exe -o bin\Debug\SampleProject.exe obj\Debug\hello.o Output file is bin\Debug\SampleProject.exe with size 117.34 KB

————–

 

If you are using a text editor with the GCC compiler, start a command prompt, change the directory to your work location and issue the command, something like:

/> gcc -o hello.exe hello.c

Run the Project

Run the Executable Code. To run the project Hit the Run menu option (Ctrl -F10)  

The IDE used in the program is Code:: Blocks. To download and install Code Blocks follow the link:

https://www.testingdocs.com/download-and-install-codeblocks/

For more information on Code Blocks IDE, visit the official website of Code blocks IDE: http://www.codeblocks.org/

Exit mobile version