Friday 25 January 2013

Introduction to C

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.

No comments:

Post a Comment