Search This Blog

Monday, June 27, 2011

C Programming – Ch:001 – Introduction

 

visit www.iGnani.com

Click here for the Video Tutorial of this article.

Hello and welcome to C Programming from iGnani.com. This course will teach you to learn how to program in C Language. We start with an introductory level for beginners and take it the advanced level.

This tutorial is a team effort by a few individuals who have been using C as their language of development at their work places.

We will be following the book published by Brian Kernighan and Dennis Ritchie known to C programmers as “K&R”. Though we use this book as the main reference for our tutorial, we have used various other materials shared by like-minded people on the internet, the references for them will be mentioned as and where we use as per the copyright & license.

We will be using Windows platform to learn C, hence we use tools that are Windows platform based. However, you should not have any problems in running the sample programs on Linux as well. I will give you details about them as and when we start to use them.

Every problem can be solved in a lot of different ways and you can also achieve the solution, but getting a solution which is exactly what you need, with speed, efficient, minimal error and highly optimized is something incredibly difficult, even for the experts. For example, you can consider building a house. If your customer asks for just a house with few rooms, every architect you meet will give you a different solution. In the same way solving complex problems you will have many different solutions, but you should have the capability to provide what is best.

We are not going to provide you with answers to all the problems out there and you know that it is impossible. Our goal here is to provide you with a variety of code samples on each and every possible topic related to Programming in C. There are already several other tutorials and books out there on C Programming. Many of them are quite good and cover almost all of C, but also cost you to pay for them. While there is also a vast ocean of tutorials on the net for free, most of them are in text and are scattered around. Some cover almost everything, but they focus on the basics, not on providing enough code samples. That is, they cover basic programming principles and explain how to do it, but not through examples on how, which can be surprisingly difficult while learning.

Of course, just going through this course or the related code might just get you some knowledge on C Programming; but you will have to write and run your own programs over and above what we have provided until you are comfortable in each of the concepts that we have covered. Though we provide almost all the example problems and more in individual files ready to be compiled and executed, we strongly recommend you to type each and every character yourself. Almost all the assignments are provided along with their solution code. Please do not peek at them until you've given the problems your best shot! Remember you are trying these videos to learn C for yourself and not for others.

Finally, this tutorial is for all those people who would want to learn programming in C or for those who would want to brush up their skills or for those who would want to gain some more knowledge than what they already know. Depending on your background, you might want to cover all the videos in an order and try out all the samples we have provided or just what is relevant to you based on your requirements. But we do suggest you to try out all the videos and at least one sample from each topic for you to get proper benefit from this course.

Prerequisites: This tutorial is aimed at Level 002 category of people, who understand the basic concepts of Computers and how they work. This course does not require people to have any programming knowledge. But we do suggest people to have completed our tutorials on “Computer Fundamentals Part 1 & 2” and “Computer Programming” tutorials at iGnani. As with any other such course, the more knowledge you have when starting the course, the more you’ll get from this course.

Introduction

Before you jump in and start to write some programs in C Language, it would be interesting to find out what really is C, and before that we should really know what is Programming.

We have covered in detail about what exactly is programming and related topics in our course “Computer Programming”. Please feel free to complete that before you proceed with this course in case if you have any questions regarding what is programming.

 

What is Programming?

Computer programming commonly known as programming or coding is the art of making a computer do what you want it to do. Programming in very simple terms is about writing programs. A sequence of instructions written to perform a specified task for a computer is known commonly as a Program, but is also referred to as a Software Program or even Computer Program. A computer being just hardware requires instructions to act upon. These instructions are executed in the computes CPU.

Somehow over the years, for most common people consider programming as a job that pays very huge sum of salary for writing something which they don’t have a clue of. Also people have come to associate programming with mathematics, complex logic and various other complicated things, though I never quite understood that. Programming is like any other profession, which demands the required skill and knowledge to achieve your goals. However you should have the capability to understand the problem and know the way to achieve it. If you know the steps to solve the problem then it’s simple to put it into code. I’ve known some really good programmers who had zero math skills. Some people are naturally good in programming and pick it up quickly, while others not so good and quick take time. In case of the latter, they need enough patience and lot of practice to learn programming.

I am not going to go into more details on the topic Programming. So let us move onto our next question,

 

Why do we need Programming Languages?

Why can’t we use something like English? And the answer to this question is that:

  • A Computer is a dumb box, which cannot understand English.
  • Computers need precise instructions and English would make a lousy programming language.

To explain our first point above, Since a Computer being a machine only understands two basic concepts: on and off. The on and off concept is called binary system with on representing 1 and off representing 0. Hence Computer knows only one language that is of 0’s and 1’s commonly known as binary language.

To explain the second point, English as a language is packed with full of ambiguities and it is very hard to express something in an unambiguous way using English. I hope that my statement that I have made now it-self will raise lot of questions.

Programming languages has answers to both of these problems. They are simple enough to be translated by translators known as Compilers or Interpreters which can convert these programming languages into binary code understandable by machines and these programming languages also reduce ambiguity.

There are a lot of different programming languages available and to be competitive in today’s world, you should know at least more than one.

In this course we will be learning the C Language.


 

What is C?

image
     Dennis Ritchie

C is a general-purpose computer programming language developed by Dennis Ritchie. The initial development of C occurred at “AT&T Bell Labs between 1969 and 1973. It was named "C" because its features were derived from an earlier language called “B”, which according to Ken Thompson was a stripped-down version of the BCPL programming language.

The origin of C is closely tied to the development of the UNIX operating system, originally implemented in assembly language on a PDP-7 by Ritchie and Thompson, incorporating several ideas from colleagues. Eventually they decided to port the operating system to a PDP-11. B's inability to take advantage of some of the PDP-11's features, notably byte addressability, led to the development of an early version of C.

The original PDP-11 version of the UNIX system was developed in assembly language. By 1973, with the addition of struct types, the C language had become powerful enough that most of the UNIX kernel was rewritten in C. This was one of the first operating system kernels implemented in a language other than assembly.

Although C was designed for implementing system software, it is also widely used for developing portable application software.

C is one of the most popular programming languages of all time and there are very few computer architectures for which a C compiler does not exist. C has greatly influenced many other popular programming languages, most notably C++, which began as an extension to C.

 

K&R C

image

Brian Kernighan and Dennis Ritchie published the first edition of “The C Programming Language” in the year 1978. This book, known to C programmers as "K&R", served for many years as an informal specification of the language. The version of C that it describes is commonly referred to as K&R C. The second edition of the book covers the later ANSI C standard.

ANSI C was followed by a lot of other standards, the latest being the “C1X” in the year 2007. As of today June 2011, the new standard is not yet finalized. The most recent working draft, N1570, was published in April 2011. This goes on to prove that C is very much active and evolving even after being one of the earliest languages.

Furthermore, in an industry where newer languages, tools and technologies appear and disappear every day, a language that has survived for more than 4 decades has to be really worthy.

image
        Brian Kernighan


 

Uses

C can be and has been used in almost all areas of computers. Often some people say that “C has been already super ceded by languages like C++, C#, Java, and so on. So why bother to learn C today”. But its usages goes onto speak of something very different. I would like to mention that what I am referring to is not all that can be achieved using C language.

  • C is often used for "system programming", including implementing operating systems and embedded system applications, due to a combination of desirable characteristics such as:
    • Code portability and efficiency
    • Ability to access specific hardware addresses
    • Ability to pun types to match externally imposed data access requirements, and
    • Low run-time demand on system resources.
  • C can also be used for website programming using CGI as a "gateway" for information between the Web application, the server, and the browser.
  • Some reasons for choosing C over interpreted languages are its speed, stability, and near-universal availability.
  • One consequence of C's wide acceptance and efficiency is that compilers, libraries, and interpreters of other programming languages are often implemented in C. The primary implementations of Python (CPython), Perl 5, and PHP are all written in C.
  • Due to its thin layer of abstraction and low overhead, C allows efficient implementations of algorithms and data structures, which is useful for programs that perform a lot of computations. For example, the GNU Multi-Precision Library, the GNU Scientific Library, Mathematica and MATLAB are completely or partially written in C.
  • C is sometimes used as an intermediate language by implementations of other languages. This approach may be used for portability or convenience; by using C as an intermediate language, it is not necessary to develop machine-specific code generators. Some languages and compilers which have used C this way are BitC, C++, COBOL, Eiffel, Gambit, GHC, Squeak, and Vala.
    However, C was designed as a programming language, not as a compiler target language, and is thus less than ideal for use as an intermediate language. This has led to development of C-based intermediate languages such as C--.
  • Major parts of popular operating systems like Windows, UNIX, and Linux are written in C. This is because even today when it comes to performance, C beats everything. Most of the device driver programs are also written in C.
  • The programs that are used in Mobile Phones, Microwave Oven, Washing Machine, Camcorders, Digital Cameras, TV’s are all written in C, due to the constraints of limited memory and processor speed but still requires optimal performance.

C has also been widely used to implement end-user applications, but much of that development has shifted to newer languages.

In our next article, let us start with knowing “How C Programming Works” and continue from there on.

Click here for the Video Tutorial of this article.

visit www.iGnani.com

No comments:

Post a Comment