Saturday, 19 November 2011

Lesson 2 : First C Program

Now Friends, that you are well equipped with the knowledge of keywords and identifiers, let us write a simple program to calculate the sum of two numbers entered by user.

#include<stdio.h>
void main()
{
 int a,b,sum;
 printf("Enter two numbers");
 scanf("%d %d " ,&a ,&b);
 sum=a+b;
 printf("Sum = %d ");
}

this program will have a output like this
Enter two numbers 10 20
Sum = 30

Here in this program you can see few things, let us look at them line by line.
1. The first line contains "#include<stdio.h>" this is known as preprocessor. It says the compiler to include library file "stdio.h". ".h" represents a header file. This file contains the details for functions like printf, scanf and other input-output functions.

2. The 2nd line have void main() this is where our compiler starts reading the program. Every C program must contain one and only one main() function because this is were the compiler starts reading and executing the program. The void before the main declares that the program will not return anything. We'll get to it later.

3. Every program is written within a pair of curly braces. This defines the area as well as the limit for a program.

4." int a,b,sum; " this is a declaration statement. It means that variable a, b and sum has been declared and all of them are integers.

5. printf is a output functions whose work is to display or we can say print the characters written within the pair of inverted commas.

6. scanf is another C function which will take the value entered by the user and store it in variable a, and b respectively.

7. "sum=a+b;" this is an arthematic expression defined by us. It tells the computer to add a and b and store its value in sum. In C, there are many arthematic operators , they are " +, -, * , / ,% ". You might be familiar with the first four operators but the last one you might not be knowing. Well, its called modulus operator. what it does is return the remainder of the divided number. For example "3%2" will give 1 as an answer.

8. I think you might now have probably guess what the last statement is doing. It is printing the value of sum on the output screen.

You might have noticed that after some lines i have put an semicolon (;), this represents a C statement. Every C statement ends with a semicolon. Its like ending a sentence with full stop. Try making a program that will subtract one number from other till next class.

Enjoy :)

Monday, 14 November 2011

Lesson 1 : Getting Started With C

Now all you guys know why you should be starting with C and then Getting to C++ lets begin our 1st lesson for C. We all know very well that C is a language and a language have some alphabets, combination of which results in words and then several words together create sentences. So , there is the case with the C, C has got keywords, and identifiers, combination of which results in the statement and if the statement is correct then C executes it without error.
You guys now might be wondering that what are keywords and identifiers, don't worry i'll tell you what they are and how to use them. Keywords are predefined C words that have already defined meaning like int, which means a integer is being defined. There are many Keywords that you will get to know as we will proceed. Now, Identifiers, are those words which are defined by the programmer, that is, you to store some values. It could be any word other than keywords. There are few rules for defining Identifiers that you should keep in mind while defining them.They are :

  1.  A variable name(identifier) is any combination of 1 to 31 alphabets, digits or underscores.
  2. The first character in the variable name must be an alphabet or underscore.
  3. No commas or blanks are allowed within a variable name.
  4. No special symbol other than an underscore (as in gross_sal) can be used in a variable name.
Now you all might be wondering what are the use of these identifiers(variables). Well, as i said earlier they are used to store values so if we need to retrieve that value again we need to know the address of the value and thus to get that very same value we need we create identifiers.

Values stored under identifiers are of five types and these types are called data types. They are 
  • Character(char)
  • Integer(int)
  • Real Number(float)
  • Double(extended Float)
  • Void
I am going to define each of this before finishing this weeks lesson.
Character : This type of variable is used to store words or alphabets like mango, ant, a. If a single inverted comma is put before and after the alphabet it will store its ASCII value. 
e.g  char 'd' will be give the value 100.
Integer : This type of variable is used to store integer value that is 1,43, 32 
Float : This data type is used to store real values like 1.232, 43.22 and so on.
Double : It is same as Float but with extended decimal points
Void : This is an empty data type.

Hope you get all the details for this chapter, grasp it well as it will form the basic for you serious programming objectives.

Thursday, 10 November 2011

Introduction To C

Before we can start writing serious programs in C, it would be interesting to know what it is C, how it came into existence and how it compares with other languages. This post briefly summarizes these issues.

Four important aspects of any language are the way it stores data, how it operates on these data, how it performs input and output and how you control the execution sequence of instructions in a program . I would like to discuss the first three of these building blocks in this post.

What is C?
C is a programming language developed at Bell Laboratories AT & T U.S. in 1972. It was designed and written by a man named Dennis Ritchie. In the seventies C began to replace the language of the era known as PL / I, ALGOL, etc. No one pushed C. There was no "official" Bell Labs, language. Therefore, without any advertising and its reputation spread C user group grew. Ritchie seems to have been quite surprised that many programmers prefer C to the ancient languages ​​such as FORTRAN or PL / I, or the newer ones, such as Pascal and APL. But, that's what happened.
Possibly why C seems so popular is because it is reliable, simple and easy to use. Moreover, in an industry where new languages, tools and technologies emerge and vanish day by day, a language that has survived for over three decades has to be really good.
An opinion that is often heard today is - "C has been superseded by other languages ​​like C + +, C # and Java, so why  C learn today. "I seriously disagree with this view. There are several reasons for this:

(A). I think nobody can learn C + + or Java directly. This is because while learning languages ​​have things like classes, objects, inheritance, polymorphism, templates, exception handling, references, etc. involved in addition to knowing the elements of the current language. Learning these complicated concepts when it is not even comfortable with the basics of the language is like putting the cart before the horse. Therefore, they must first learn all the elements of a language very well using the C language before migrating to C + +, C # or Java. Although this two-step process of learning can take longer, but eventually you will definitely find it worth the hassle.

(B).C + +, C # or Java to use a principle called Object Oriented Programming (OOP) to organize the program. This organizing principle has a lot of advantages to offer. But even while using this principle of organization that would still need a good grip on the language elements of C and basic programming skills.

(C).Although many C + + and Java-based programming frameworks have evolved over the years the importance of the C is still unanswered, because knowingly or unknowingly while using these frameworks and tools are still required to use the core C language elements-another good reason for one to learn C before C + +, C # or Java.

(D).The main parts of popular operating systems including Windows, UNIX, Linux is still written in C. This is because even today, when it comes to performance (execution speed) there is nothing like C. On the other hand, if you extend the operating system to work with new devices needed to write software drivers. These programs are exclusively written in C.

There certainly are many reasons for you to know why C is needed by all of us but I hope these are very compelling reasons why one should take C as the first and important step in their quest for learning programming languages.

Wednesday, 9 November 2011

Introduction To Blog

Hello Dear Friends,
I have taken an initiative to write this blog for all of the novice programmers who wants to learn C and C++ for free and with all the details that other such websites do not provide. I will be providing you with all the details for C programming and also with the exercise that will help you get better. There will be a lesson a week, means i will be increasing the matter every week. So if you are paying or going to coaching for learning this language then you won't be needing to do so.
I will be beginning my classes from  21 November, with the introduction to C . Hang on here.


If you are willing to ask any question related to any topic that you have learned you are free to do so by posting comments on the blog with you emails, i will get back to you there.

5JY9JVACZ66W