Your Ad Here

Sunday, April 27, 2008

Our First 'C' Program

Today, we will create a simple 'C' program which would read a number from the keyboard and would display it on the screen.

#include<stdio.h>//Include these files for using standard input and output functions
#include<conio.h>
void main(void)
{
int num; //Define an integer variable which would store a number
printf("Enter a number:"); //This would print on the screen "Eenter a number:"
scanf("%d", &num); //This would allow the user to enter a number
printf("Number : %d", num); //Prints the entered number back to the screen
getch();
}

There are many things which can be noticed in this sample program and which can confuse us, lets focus on a few things.

Question 1: Why do we have a semi colon ; after every statement inside main function?
Answer: 'C' compiler marks an end of the statement wherver it finds a semicolon. It would be easier if if take it this way, in English whenever we want to mark the end of a sentence, we put a full stop (.), but in case of 'C' language we put a (;) semi colon.

Question 2: Why do we have "int" written before num, what does it denote?
Answer: 'C' language has got certain data types, these data types can store different types of data in them, for instance integers, floating point numbers, characters, strings etc. The syntax of using these data types is:

datatype variablename;
e.g.
int num; // As in our example

Now, for storing values between -32768 to +32767 we use int data type, this data type requires 2 bytes of memory and the keyword in 'C' for this is 'int'.


In the next post I will answer a few more questions on this sample program we made today.

Saturday, April 19, 2008

Skeleton of a 'C' Program

C is a structured language and everything which need to be coded or programmed must be structured in nature, for those who don't know what is structured programming can follow one of the links availbale.

We will start with understanding the basic programming construct in 'C language'.

Sample Program:
#include
#include
void main()
{
printf("Hello World");
}

Point # 1:The most important thing in this program is "#include", these are called preprocessor directives in C language, it is denoted by # symbol. 'C' does not support dynamic linking, statis linking means everything which needs to be included becomes part of the executable file. So, when I wrote #include, there is a process called preprocessing which happens before compilation in 'C', it copies the content of the file specifed at the place of this statement, In our case the content of the file stdio.h will be placed in the place of #include. After the precprocessing is complete, compilation start which eventually creates the executable.

Ponit #2:
What is main() here, main is a function, a function is a small block of code which executes together. But why do we name it main?, we could have had 'small', 'big' etc. but why 'main', the answer is every function needs to be called for execution and because every application runs under the Operating System, OS is the one who starts the execution, but the OS is programmed to call only function named 'main', we can say 'main' function is the entry to the application. All other function written are called by main as and when required.

In the next post we would discuss about the standard input and output functions.

Saturday, April 12, 2008

Let’s Begin

7 Years ago when I decided to change and join IT industry, the first programming language I came across was C language. I was told by others that this would be my ultimate test of intelligence as they were finding it pretty difficult to cope with. Whatever I learnt till that point of time was kind of a walkover for me.

Then the day arrived when we were supposed to attend our first C language session, the session began and the first line from our tutor made it clear for me that how important it was to know C language to succeed in Software industry. He said, “This language is mother of all the High Level Languages that have existed and will be in the future as well.” Everyone knows how valid those comments were, all the languages which I have worked on till date, seem to have something from this language. C++, JAVA, VB 6.0, C#, pick anyone you like, you would feel as if it has got it roots in C.

We will start our first technical discussion from the next post.

Sunday, April 6, 2008

C language, no longer a mirage...

Hey people,
For the last 4 years I have been into IT industry and have met a lot of people across the globe. I have found one thing common in all of them, especially the beginners, they are scared of 'C' language or we can say that 'C' language is like mirage to them, the closer they get, more difficult they find it to understand.

My purpose of starting this blog is to create a network or a central place where we could share our knowledge on 'C', especially for those who are new to this industry and find it challenging to break the intial barrier.

I would be posting a lesson every day on this blog and you will also find some really usefull links to other sites.

I welcome you all,
Sankalp