Beginning with C Programming
Beginning with C Programming
1️⃣ Finding a Compiler
Before starting C programming, you need a compiler to compile and run programs.
✔ Online C Compilers (No Installation Needed)
You can use:
These allow you to write and run C programs directly in the browser.
2️⃣ Compilers for Different Operating Systems
🪟 Windows
Free C compilers available:
Code::Blocks
Dev-C++
Borland C
https://developerinsider.co/download-and-install-borland-c-compiler-on-windows-10/
🐧 Linux
GCC usually comes bundled with Linux
Code::Blocks can also be used
This guide is based on Linux (Ubuntu) and examples are compiled on Ubuntu.
3️⃣ Check if GCC is Installed (Linux/UNIX)
Open terminal and type:
If GCC is installed → version information will be displayed
If not installed → follow instructions:
4️⃣ Writing Your First C Program
Example Program
Output
5️⃣ Program Explanation (Line by Line)
Line 0
Multi-line comments use
/* */Comments are ignored by the compiler
Improve readability and documentation
Single-line comments use
//
Line 1
Lines starting with
#are processed by the preprocessorPreprocessor converts the program before compilation
stdio.his a header fileContains declarations for functions like
printf()
Line 2
Entry point of the C program
Execution begins from
main()void→ no parameters passedint→ return type of the functionReturned value indicates program termination status
Line 3 and Line 6
Curly braces define scope
Used in functions, loops, conditions
Every function must start and end with
{}
Line 4
Standard library function for output
Prints text to screen
Semicolon
;marks end of statementMandatory in C
6️⃣ Compile and Execute a C Program
Follow these steps:
Step 1: Open a text editor
Examples:
Step 2: Save file as
Step 3: Go to the directory containing the file
Step 4: Compile the program
If no errors occur, an executable file is created:
Step 5: Run the program
Output
✔ Important Notes
Ensure gcc is installed
Ensure gcc is in your system PATH
Run the command from the directory containing
hello.c
Comments
Post a Comment