x-pert
06-30-2007, 10:03 PM
C is a programming language that allows a software engineer to efficiently communicate with a computer.
C is a highly flexible and adaptable language. Since its creation in 1970, it's been used for a wide variety of programs including firmware for micro -controllers, operating systems, applications, and graphics programming.
C is one of the most widely used languages in the world and is fairly stable. An improved C language called C++ has been invented.
C++, originally known as C with Classes, adds a number of new features to the C language, the most important of which is the class. Classes facilitate code reuse through object-oriented design (OOD).
Which is better, C or C++? The answer depends on who you talk to. C++ does great things for you behind your back, such as automatically calling constructors and destructors for variables. This processing makes some types of programming easy, but it makes static checking of programs difficult, and you need to be able to tell exactly what your program is doing if you are working on embedded control applications. So some people consider C++ the better language because it does things automatically and C doesn't. Other people consider C better for precisely the same reason.
But now this is the era of C#... It is a much more powerful language. We’ll discuss about it later.... ;)
Communicating with computers is not easy. They require instructions that are exact and detailed. It would be nice if we could write programs in English. Then we could tell the computer, "My User name is x-pert and my password is ******, so log me in http://www.elakiri.com," and the machine would log me in to EK.
But English is a lousy language when it comes to writing exact instructions. The language is full of ambiguity and imprecision.
So English, with all its problems, is out. Now, how do we communicate with a computer?
The first computers cost millions of dollars, while at the same time a good programmer cost about $15,000 a year. Programmers were forced to program in a language in which all the instructions were reduced to a series of numbers, called machine language. This language could be directly input into the computer.
A typical machine-language program looks like:
1010 1111
0011 0111
0111 0110
.. and so on for several hundred instructions
While machines "think" in numbers, people don't. To program these ancient machines, software engineers would write their programs using a simple language in which each word in the language stood for a single instruction. This language was called assembly language because the programmers had to hand translate, or assemble, each line into machine code.
A typical program might look like:
Program Translation
MOV A,47 1 010 1111
ADD A,B 0011 0111
HALT 0111 0110
.. and so on for several hundred instructions
Translation was a difficult, tedious, and exacting task. One software engineer decided that this was a perfect job for a computer, so he wrote a program called an assembler that would do the job automatically.
He showed his new creation to his boss and was immediately chewed out:
"How dare you even think of using such an expensive machine for a mere ‘clerical’ task." Given the cost of an hour of computer time versus the cost of an hour of programmer time, this attitude was not unreasonable.
Fortunately, as time passed the cost of programmers went up and the cost of computers went down. So letting the programmers write programs in assembly language and then using a program called an assembler to translate them into machine language became very cost effective.
Assembly language organized programs in a way that was easy for the programmers to understand. However, the program was more difficult for the machine to use. The program had to be translated before the machine could execute it. This method was the start of a trend. Programming languages became more and more convenient for the programmer to use, and started requiring more and more computer time for translation into something useful.
Over the years, a series of higher-level languages have been devised.
These languages attempt to let the programmer write in a medium that is easy for him to understand, and that is also precise and simple enough for the computer to understand. Early high-level languages were designed to handle specific types of applications. FORTRAN was designed for number crunching, COBOL was for writing business reports, and PASCAL was for student use.
In 1970 a programmer, Dennis Ritchie, created a new language called C. (The name came about because it superceded the old programming language he was using: B.) C was designed with one goal in mind: writing operating systems....
The language was extremely simple and flexible, and soon was used for many different types of programs. It quickly became one of the most popular programming languages in the world. C's popularity was due to two major factors.
Language didn't get in the way of the programmer. He could do just about anything by using the proper C construct.
Portable C compiler was widely available. Consequently, people could attach a C compiler for their machine easily and with little expense.
In 1980, Bjarne Stroustrup started working on a new language, called "C with Classes." This language improved on C by adding a number of new features. This new language was improved and augmented, and finally became C++.
One of the newest languages, C# and Java, is based on C++. Java was
designed to be "C++ with the bugs fixed."
C is designed as a bridge between the programmer and the raw computer. The idea is to let the programmer organize a program in a way that he can easily understand. The compiler then translates the language into something that the machine can use.
Computer programs consist of two main parts: data and instructions.
The computer imposes little or no organization on these two parts. After all, computers are designed to be as general as possible. The programmer should impose his organization on the computer, not the other way around.
The data in a computer is stored as a series of bytes.
C organizes those bytes into useful data. Data declarations are used by the programmer to describe the information he is working with.
For example:
int total; /* This means that there will is an integer data type named as total in this program */
Tells C that we want to use a section of the computer's memory to store an integer named total. Our variable total is a simple variable. It can hold only one integer and describe only one total. A series of integers can be organized into an array as follows:
int balance[100]; /* There are (We have stored) 100 integers in an array called balance */
Again, C will handle the details of imposing that organization on the computer's memory. Finally, there are more complex data types. For example, a rectangle might have a width, a height, a color, and a fill pattern. C lets us organize these four items into one group called a structure.
struct rectangle
{
int width; /* Integer named width */
int height; /* integer named height which we can use to store the height of the rectangle */
color_type color; /* Color of the rectangle */
fill_type fill; /* Fill pattern */
};
The point is that structures allow the programmer to arrange the data to suit his needs no matter how simple or complex that data is. Translation of this data description into something the computer can use is the job of the compiler, not the programmer.
But data is only one part of a program. We also need instructions. As far as the computer is concerned, it knows nothing about the layout of the instructions. It knows what it's doing for the current instruction and where to get the next one, but nothing more.
C is a high-level language. It lets us write a high-level statement like:
area = (base * height) / 2.0; /* :lol: this is the formula to calculate the area of an triangle... (baagaya X aadaarakaya X lambha usa) */
The compiler will translate this statement into a series of cryptic low-level machine instructions. This sort of statement is called an assignment statement. It is used to compute and store the value of an arithmetic expression.
We can also use control statements to control the order of processing. Statements like the if and switch statements enable the computer to make simple decisions. Statements can be repeated over and over again by using looping statements such as while and for.
Groups of statements can be wrapped to form functions. Thus, we only have to write a general-purpose function to draw a rectangle once, and then we can reuse it whenever we want to draw a new rectangle.
C provides the program with a rich set of standard functions that perform common functions such as searching, sorting, input, and output.
A set of related functions can be grouped together in a single source file. Many source files can be compiled and linked together to form a program.
One of the major goals of the C language is to organize instructions into reusable components. After all, you can write programs much faster if you can "borrow" most of your code from somewhere else. Groups of reusable functions can be combined into a library. In this manner, when you need, for example, a sort routine, you can grab the standard function qsort from the library and link it into your program.
All the C language elements are designed to allow the programmer to express and organize his ideas clearly in a manner tailored to him, not to the computer.
Organization is the key to writing good programs. For example, think about a table of contents in a book.... Table of Contents is in the front. We use this structure because books are organized that way. Organization makes the book easier to use.
So is C.... :D
References : Oualline S, Practical C Programming 3rd ed., O'Reily publications,
Stroustrup B, The C++ Programming language sp edn., AT & T Labs.
C is a highly flexible and adaptable language. Since its creation in 1970, it's been used for a wide variety of programs including firmware for micro -controllers, operating systems, applications, and graphics programming.
C is one of the most widely used languages in the world and is fairly stable. An improved C language called C++ has been invented.
C++, originally known as C with Classes, adds a number of new features to the C language, the most important of which is the class. Classes facilitate code reuse through object-oriented design (OOD).
Which is better, C or C++? The answer depends on who you talk to. C++ does great things for you behind your back, such as automatically calling constructors and destructors for variables. This processing makes some types of programming easy, but it makes static checking of programs difficult, and you need to be able to tell exactly what your program is doing if you are working on embedded control applications. So some people consider C++ the better language because it does things automatically and C doesn't. Other people consider C better for precisely the same reason.
But now this is the era of C#... It is a much more powerful language. We’ll discuss about it later.... ;)
Communicating with computers is not easy. They require instructions that are exact and detailed. It would be nice if we could write programs in English. Then we could tell the computer, "My User name is x-pert and my password is ******, so log me in http://www.elakiri.com," and the machine would log me in to EK.
But English is a lousy language when it comes to writing exact instructions. The language is full of ambiguity and imprecision.
So English, with all its problems, is out. Now, how do we communicate with a computer?
The first computers cost millions of dollars, while at the same time a good programmer cost about $15,000 a year. Programmers were forced to program in a language in which all the instructions were reduced to a series of numbers, called machine language. This language could be directly input into the computer.
A typical machine-language program looks like:
1010 1111
0011 0111
0111 0110
.. and so on for several hundred instructions
While machines "think" in numbers, people don't. To program these ancient machines, software engineers would write their programs using a simple language in which each word in the language stood for a single instruction. This language was called assembly language because the programmers had to hand translate, or assemble, each line into machine code.
A typical program might look like:
Program Translation
MOV A,47 1 010 1111
ADD A,B 0011 0111
HALT 0111 0110
.. and so on for several hundred instructions
Translation was a difficult, tedious, and exacting task. One software engineer decided that this was a perfect job for a computer, so he wrote a program called an assembler that would do the job automatically.
He showed his new creation to his boss and was immediately chewed out:
"How dare you even think of using such an expensive machine for a mere ‘clerical’ task." Given the cost of an hour of computer time versus the cost of an hour of programmer time, this attitude was not unreasonable.
Fortunately, as time passed the cost of programmers went up and the cost of computers went down. So letting the programmers write programs in assembly language and then using a program called an assembler to translate them into machine language became very cost effective.
Assembly language organized programs in a way that was easy for the programmers to understand. However, the program was more difficult for the machine to use. The program had to be translated before the machine could execute it. This method was the start of a trend. Programming languages became more and more convenient for the programmer to use, and started requiring more and more computer time for translation into something useful.
Over the years, a series of higher-level languages have been devised.
These languages attempt to let the programmer write in a medium that is easy for him to understand, and that is also precise and simple enough for the computer to understand. Early high-level languages were designed to handle specific types of applications. FORTRAN was designed for number crunching, COBOL was for writing business reports, and PASCAL was for student use.
In 1970 a programmer, Dennis Ritchie, created a new language called C. (The name came about because it superceded the old programming language he was using: B.) C was designed with one goal in mind: writing operating systems....
The language was extremely simple and flexible, and soon was used for many different types of programs. It quickly became one of the most popular programming languages in the world. C's popularity was due to two major factors.
Language didn't get in the way of the programmer. He could do just about anything by using the proper C construct.
Portable C compiler was widely available. Consequently, people could attach a C compiler for their machine easily and with little expense.
In 1980, Bjarne Stroustrup started working on a new language, called "C with Classes." This language improved on C by adding a number of new features. This new language was improved and augmented, and finally became C++.
One of the newest languages, C# and Java, is based on C++. Java was
designed to be "C++ with the bugs fixed."
C is designed as a bridge between the programmer and the raw computer. The idea is to let the programmer organize a program in a way that he can easily understand. The compiler then translates the language into something that the machine can use.
Computer programs consist of two main parts: data and instructions.
The computer imposes little or no organization on these two parts. After all, computers are designed to be as general as possible. The programmer should impose his organization on the computer, not the other way around.
The data in a computer is stored as a series of bytes.
C organizes those bytes into useful data. Data declarations are used by the programmer to describe the information he is working with.
For example:
int total; /* This means that there will is an integer data type named as total in this program */
Tells C that we want to use a section of the computer's memory to store an integer named total. Our variable total is a simple variable. It can hold only one integer and describe only one total. A series of integers can be organized into an array as follows:
int balance[100]; /* There are (We have stored) 100 integers in an array called balance */
Again, C will handle the details of imposing that organization on the computer's memory. Finally, there are more complex data types. For example, a rectangle might have a width, a height, a color, and a fill pattern. C lets us organize these four items into one group called a structure.
struct rectangle
{
int width; /* Integer named width */
int height; /* integer named height which we can use to store the height of the rectangle */
color_type color; /* Color of the rectangle */
fill_type fill; /* Fill pattern */
};
The point is that structures allow the programmer to arrange the data to suit his needs no matter how simple or complex that data is. Translation of this data description into something the computer can use is the job of the compiler, not the programmer.
But data is only one part of a program. We also need instructions. As far as the computer is concerned, it knows nothing about the layout of the instructions. It knows what it's doing for the current instruction and where to get the next one, but nothing more.
C is a high-level language. It lets us write a high-level statement like:
area = (base * height) / 2.0; /* :lol: this is the formula to calculate the area of an triangle... (baagaya X aadaarakaya X lambha usa) */
The compiler will translate this statement into a series of cryptic low-level machine instructions. This sort of statement is called an assignment statement. It is used to compute and store the value of an arithmetic expression.
We can also use control statements to control the order of processing. Statements like the if and switch statements enable the computer to make simple decisions. Statements can be repeated over and over again by using looping statements such as while and for.
Groups of statements can be wrapped to form functions. Thus, we only have to write a general-purpose function to draw a rectangle once, and then we can reuse it whenever we want to draw a new rectangle.
C provides the program with a rich set of standard functions that perform common functions such as searching, sorting, input, and output.
A set of related functions can be grouped together in a single source file. Many source files can be compiled and linked together to form a program.
One of the major goals of the C language is to organize instructions into reusable components. After all, you can write programs much faster if you can "borrow" most of your code from somewhere else. Groups of reusable functions can be combined into a library. In this manner, when you need, for example, a sort routine, you can grab the standard function qsort from the library and link it into your program.
All the C language elements are designed to allow the programmer to express and organize his ideas clearly in a manner tailored to him, not to the computer.
Organization is the key to writing good programs. For example, think about a table of contents in a book.... Table of Contents is in the front. We use this structure because books are organized that way. Organization makes the book easier to use.
So is C.... :D
References : Oualline S, Practical C Programming 3rd ed., O'Reily publications,
Stroustrup B, The C++ Programming language sp edn., AT & T Labs.