Wednesday, 20 March 2013

Introduction to C Programming - Part II

Welcome back to series of articles on Introduction to C Programming. In this article you are going to learn the very basic structure of a C Program.

Basic Structure of C Program:-

        Preprocessor Statements

        Global Declarations

        int main()

        {

           Local Declarations

           Statement(1);

           Statement(2);

           ------------------

           ------------------

           Statement(n);

          return int_value;

       }

       User Defined Functions

 

  Example:-

    #include <stdio.h> //Preprocessor statement
#define PI 3.1416

const float radius=10.5; //Global declaration

int main()
{
float circumfernce; //Local declaration
circumfernce=findCicrum(); //User defined function call
printf("Circumference of the circle is %f",circumfernce); //printing the output
return 0;
}

float findCircum() //User defined function
{
return 2*PI*radius;
}

I will explain the parts, taking one by one.

1.Preprocessor Part:-

   Preproessor part as it's name suggests, is the set of statements which  will be executed at the beginning of the compilation. The preprocessor directives abilities to include header files, defining and expanding macros, conditional compilation and also for line control. At this level we are going to talk about only the preprocessor statements for including header files and for defining macros.

   1.I ncluding Header Files:-

        A header file is a file that allows programmers to separate certain elements of a program's source code into reusable files. Header files commonly contain forward declarations of classes, subroutines, variables, and other identifiers.

    General Syntax For Including header files in C :

           Type 1]      #include <filename>

                                   In this type the compiler will search for the file specified by the filename in the standard header file's directory.

                                   In our above program we used '#include<stdio.h>'  so that the compiler will search for a file stdio.h in the stnadrad  header files directory.

 

           Type 2] #include "filename"

                                   In this type the compiler will search for the file specified by the filename preferably in the project directory and also in all directories associated with the project.

 

 


        


Sunday, 17 March 2013

Introduction to C Programming - Part II

Welcome back to series of articles on Introduction to C Programming. In this article you are going to learn the very basic structure of a C Program.

Basic Structure of C Program:-

        Preprocessor Statements

        Global Declarations

        int main()

        {

           Local Declarations

           Statement(1);

           Statement(2);

           ------------------

           ------------------

           Statement(n);

          return int_value;

       }

       User Defined Functions

 

  Example:-


#include "stdio.h" //Preprocessor statement
#define PI 3.1416

const float radius=10.5; //Global declaration

int main()
{
float circumfernce; //Local declaration
circumfernce=findCicrum(); //User defined function call
printf("Circumference of the circle is %f",circumfernce); //printing the output
return 0;
}

float findCircum() //User defined function
{
return 2*PI*radius;
}

Thursday, 14 March 2013

Introduction to C Programming - Part I

Before you start with C programming you need to have some tools to write and manage your program. Below list walks you through the list of required.
1] Text Editor :-
Text editor is required to edit your source files. Even though you can do all your editing work with simple text editors like notepad, they don't provide any useful source code editing features such as syntax highlighting.
So i recomend you any of below listed text editors.
i) Notepad++
ii) JEdit
Also you can search the internet to find a more suitable editor.

2] Compiler Set :-

A compiler is a program which translates a human readable source code to machine readable instructions.
There are many compilers with different implementations of C. One of the broadly used compilers is GNU's Mingw compiler suite. You can download this from GNU Website.
Microsoft C compiler, Turbo C, Cobra are some of many compilers available.

Integrated Development Environment
Instead of using separate tools for different tasks you can use an all in one software called Integrated Development Environment or IDE in short for all editing, compiling, debugging etc. processes. There are many commercial as well as free IDEs available. I will list some of broadly used IDEs.
1. Netbeans - You can get it from Netbeans website
2. Code::Blocks -. This is an open source ide. You can get both binaries and source code from sourceforge website.( just search for it)
3. Codelite -. This also a lightweight opensource ide. You can get both binaries and source code from sourceforge website.(just search for it)
4. Eclipse -. You can get it from Eclipse website

After choosing and installing the required tools in your computer you are ready to play with C programming language.
I will continue with basic structure of a C program in Part II.