C Tutorial

C Tutorial C Language Environment Setup Execution flow of C program C printf and Scanf C Data type C Token Variable in C Operators in C Comments in C Escape Sequence in C C – Storage Classes C Decision control statement Loop Statement in C Break, continue and goto statement in C Type Casting in C Function in C Recursion in C String in C C Array Pointer in C Dynamic memory allocation C –Structure Nested Structure in C Union in C File Handling in C C pre-processor Static Function In C Sizeof In C Selection Sort In C Scope Of Variables In C Runtime Vs Compile Time In C Random Access Lseek In C Queue Implementation In C Pseudo Code In C Prototype In C Pointer To Pointer In C Pointer Arithmetic In C Passing Array To Function In C Null Character In C Merge Sort In C Macros In C Library Functions In C Memory Leak In C Int In C Goto And Labels In C Fibonacci Series In C Fflush In C Derived Data Types In C Data Types In C Const Vs Volatile In C Character Set In C Character Class Tests In C Calloc In C C Pointers Arrays In C Include In C Clrscr In C C Vs Java String Literals In C Types Of Pointers In C Variables In C Volatile In C Why C Is A Middle Level Language Infix To Postfix Program In C Ceil function in C LCM of two numbers in C Quick sort in C Static in C function pointer as argument in C Top Array Keywords in C Add two numbers using the function in C Armstrong program in C using function Array, Declaring Arrays and Array Initialization Limitations of Inline Function in C Merge and Merge sort with example in C Do-While Loop in C For Loop in C While-Loop in C Difference between while and do-while loop in C Array Of Structures in C Data Structures And Algorithms in C Types Of Structures In C How to Avoid Structure Padding in C Use of Structure in C Do WHILE LOOP in C Programming Examples For Loop in C Programming Examples Entry Control Loop in C Exit control loop in C Infinite loop in C Nested loop in C

C Language Environment Setup

To compile C program, we must have GCC compiler installed on our machine. In this C tutorial, all the examples are compiled and tested using GCC compiler. Although we can use other C compilers also, GCC provides better performance. Installation To installGCC(GNU Compiler Collection), visit official site (http://mingw.org/download/installer)and download after downloading we can install it in our system and compile or executeCand C++ program easily. There are following some step to install GCC compiler in windows.

  • Download GCC (GNU Compiler Collection)compiler software.
  • Install it inside the system.
  • Opengcc command prompt and locate to the C source file location by using command. E.g. cd d:\c-program\Document> file-name.
  • To compileC program we can use gcc hello.c
  • We can execute compiled program by using EXE file (a.exe), at the time of compilation it will automatically create an a.exe file. We can execute that executable file in a different system at the same platform.
What is Compiler in C?
Compiler is a computer program that converts the human readable (programming language) source code into another computer language (binary code). In other words, we can say that  compiler takes the code and convert in to the binary code that computer can understand easily.

List of C compilers for windows OS
There is various compiler of C & C++ language for windows that are given below:
  • CCS C Compiler
  • Turbo C
  • Minimalist GNU for Windows (MinGW)
  • Portable C Compiler
  • Clang C++
  • Digital Mars C++ Compiler
  • Intel C++
  • IBM C++
  • Visual C++ : Express Edition
  • Oracle C++
All of these above compilers for C are open source (free), but there are some other paid C compilers. We can get it for trial version:
  • Embarcadero C++
  • Edison Design Group C++
  • Green Hills C++
  • HP C++ for Unix
  • Intel C++ for Windows, Linux, and some embedded systems.
  • Microsoft C++
  • Paradigm C++
Note: In this tutorial, we used GCC Compiler andsome text editor like Notepad or Notepad++. We can also use other IDE or editor. First C Program Before starting C program, we have to follow some basic rules of the C program that are listed below:
Basic Command Description
#include <stdio.h> We have to include standard input-output library functions.
void main() It is a keyword that returns no value.
printf() This function is used to print the data on the console.
system(“cls”) This function is used to clear the output screen.
/* some comments */ We can comment any line with this symbol that comment will not visible at the time of output.
return 0; This command terminated the program ( main function) and returns 0.

Example
#include<stdio.h>
int main(){ 
/* comment section*/
printf("Hello friends"); 
return 0;
}
 

How to compile and execute the C program by using GCC compiler?
We can compile and execute the C program by using GCC compiler.
  • For Compilation
We can compile the C program by using command gcc <filen-name>. C
  • For Execution
We can execute the compiled program by writing the exe fileof the program.

Note: At the time of compilation of the C program, the “a.exe”exe file name will be created automatically but if we want to create own exe file, then the given above example will help us to understand easily.
syntax:Gcc –o .c



ADVERTISEMENT
ADVERTISEMENT