Search
Search titles only
By:
Search titles only
By:
Log in
Register
Search
Search titles only
By:
Search titles only
By:
Menu
Install the app
Install
Forums
New posts
All threads
Latest threads
New posts
Trending threads
Trending
Search forums
What's new
New posts
New ads
New profile posts
Latest activity
Free Ads
Latest reviews
Search ads
Members
Current visitors
New profile posts
Search profile posts
Contact us
Latest ads
🔒 NordVPN Premium – 3 Months
hrdilshan
Updated:
Thursday at 8:29 PM
🚀 Microsoft Office 365 Pro Plus – Lifetime Access! 🚀
hrdilshan
Updated:
Thursday at 8:28 PM
Linkedin Premium Business / Careere /Sales Navigator - 1/2/3/6/9/12 Months - Reddem Link
hrdilshan
Updated:
Thursday at 8:27 PM
Colombo
YEYE 3 in 1 Instant Coffee Mix 50 Sachet
Romeshka
Updated:
Wednesday at 12:16 AM
Colombo
Red Hat Certified System Administrator (RHCSA) - RHEL 10
Sanjeewani95
Updated:
Jul 3, 2026
Electronics
Vehicles
Property
Search
Reply to thread
Forums
Computers & Internet
Problems and Troubleshooting
Lesson 01 : C Programming
Get the App
JavaScript is disabled. For a better experience, please enable JavaScript in your browser before proceeding.
You are using an out of date browser. It may not display this or other websites correctly.
You should upgrade or use an
alternative browser
.
Message
<blockquote data-quote="x-pert" data-source="post: 638481" data-attributes="member: 837"><p><span style="font-family: 'Ariel'"><span style="font-size: 12px">C is a programming language that allows a software engineer to efficiently communicate with a computer.</span></span></p><p><span style="font-family: 'Ariel'"><span style="font-size: 12px"></span></span></p><p><span style="font-family: 'Ariel'"><span style="font-size: 12px">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.</span></span></p><p><span style="font-family: 'Ariel'"><span style="font-size: 12px"></span></span></p><p><span style="font-family: 'Ariel'"><span style="font-size: 12px">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. </span></span></p><p><span style="font-family: 'Ariel'"><span style="font-size: 12px"></span></span></p><p><span style="font-family: 'Ariel'"><span style="font-size: 12px">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). </span></span></p><p><span style="font-family: 'Ariel'"><span style="font-size: 12px"></span></span></p><p><span style="font-family: 'Ariel'"><span style="font-size: 12px">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.</span></span></p><p><span style="font-family: 'Ariel'"><span style="font-size: 12px"></span></span></p><p><span style="font-family: 'Ariel'"><span style="font-size: 12px">But now this is the era of C#... It is a much more powerful language. We’ll discuss about it later.... <img src="/styles/default/xenforo/smilies/default/wink.gif" class="smilie" loading="lazy" alt=";)" title="Wink ;)" data-shortname=";)" /></span></span></p><p><span style="font-family: 'Ariel'"><span style="font-size: 12px"></span></span></p><p><span style="font-family: 'Ariel'"><span style="font-size: 12px">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 <strong><a href="http://www.elakiri.com" target="_blank">http://www.elakiri.com</a></strong>," and the machine would log me in to EK.</span></span></p><p><span style="font-family: 'Ariel'"><span style="font-size: 12px"></span></span></p><p><span style="font-family: 'Ariel'"><span style="font-size: 12px"></span></span></p><p><span style="font-family: 'Ariel'"><span style="font-size: 12px">But English is a lousy language when it comes to writing exact instructions. The language is full of ambiguity and imprecision. </span></span></p><p><span style="font-family: 'Ariel'"><span style="font-size: 12px"></span></span></p><p><span style="font-family: 'Ariel'"><span style="font-size: 12px"></span></span></p><p><span style="font-family: 'Ariel'"><span style="font-size: 12px">So English, with all its problems, is out. Now, how do we communicate with a computer?</span></span></p><p><span style="font-family: 'Ariel'"><span style="font-size: 12px"></span></span></p><p><span style="font-family: 'Ariel'"><span style="font-size: 12px"></span></span></p><p><span style="font-family: 'Ariel'"><span style="font-size: 12px">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. </span></span></p><p><span style="font-family: 'Ariel'"><span style="font-size: 12px"></span></span></p><p><span style="font-family: 'Ariel'"><span style="font-size: 12px">A typical machine-language program looks like:</span></span></p><p><span style="font-family: 'Ariel'"><span style="font-size: 12px"><span style="font-family: 'Courier New'">1010 1111</span></span></span></p><p><span style="font-family: 'Ariel'"><span style="font-size: 12px"><span style="font-family: 'Courier New'">0011 0111</span></span></span></p><p><span style="font-family: 'Ariel'"><span style="font-size: 12px"><span style="font-family: 'Courier New'">0111 0110</span></span></span></p><p><span style="font-family: 'Ariel'"><span style="font-size: 12px"><span style="font-family: 'Courier New'">.. and so on for several hundred instructions</span></span></span></p><p><span style="font-family: 'Ariel'"><span style="font-size: 12px"></span></span></p><p><span style="font-family: 'Ariel'"><span style="font-size: 12px">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.</span></span></p><p><span style="font-family: 'Ariel'"><span style="font-size: 12px"></span></span></p><p><span style="font-family: 'Ariel'"><span style="font-size: 12px">A typical program might look like:</span></span></p><p><span style="font-family: 'Ariel'"><span style="font-size: 12px"><span style="font-family: 'Courier New'">Program Translation</span></span></span></p><p><span style="font-family: 'Ariel'"><span style="font-size: 12px"><span style="font-family: 'Courier New'">MOV A,47 1 010 1111</span></span></span></p><p><span style="font-family: 'Ariel'"><span style="font-size: 12px"><span style="font-family: 'Courier New'">ADD A,B 0011 0111</span></span></span></p><p><span style="font-family: 'Ariel'"><span style="font-size: 12px"><span style="font-family: 'Courier New'">HALT 0111 0110</span></span></span></p><p><span style="font-family: 'Ariel'"><span style="font-size: 12px"><span style="font-family: 'Courier New'">.. and so on for several hundred instructions</span></span></span></p><p><span style="font-family: 'Ariel'"><span style="font-size: 12px"></span></span></p><p><span style="font-family: 'Ariel'"><span style="font-size: 12px">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.</span></span></p><p><span style="font-family: 'Ariel'"><span style="font-size: 12px"></span></span></p><p><span style="font-family: 'Ariel'"><span style="font-size: 12px">He showed his new creation to his boss and was immediately chewed out: </span></span></p><p><span style="font-family: 'Ariel'"><span style="font-size: 12px"></span></span></p><p><span style="font-family: 'Ariel'"><span style="font-size: 12px">"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.</span></span></p><p><span style="font-family: 'Ariel'"><span style="font-size: 12px"></span></span></p><p><span style="font-family: 'Ariel'"><span style="font-size: 12px"></span></span></p><p><span style="font-family: 'Ariel'"><span style="font-size: 12px">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.</span></span></p><p><span style="font-family: 'Ariel'"><span style="font-size: 12px"></span></span></p><p><span style="font-family: 'Ariel'"><span style="font-size: 12px"></span></span></p><p><span style="font-family: 'Ariel'"><span style="font-size: 12px">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.</span></span></p><p><span style="font-family: 'Ariel'"><span style="font-size: 12px"></span></span></p><p><span style="font-family: 'Ariel'"><span style="font-size: 12px"></span></span></p><p><span style="font-family: 'Ariel'"><span style="font-size: 12px">Over the years, a series of higher-level languages have been devised. </span></span></p><p><span style="font-family: 'Ariel'"><span style="font-size: 12px"></span></span></p><p><span style="font-family: 'Ariel'"><span style="font-size: 12px"></span></span></p><p><span style="font-family: 'Ariel'"><span style="font-size: 12px">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. <strong>FORTRAN </strong>was designed for number crunching, <strong>COBOL</strong> was for writing business reports, and <strong>PASCAL</strong> was for student use. </span></span></p><p><span style="font-family: 'Ariel'"><span style="font-size: 12px"></span></span></p><p><span style="font-family: 'Ariel'"><span style="font-size: 12px"></span></span></p><p><span style="font-family: 'Ariel'"><span style="font-size: 12px">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....</span></span></p><p><span style="font-family: 'Ariel'"><span style="font-size: 12px"></span></span></p><p><span style="font-family: 'Ariel'"><span style="font-size: 12px"></span></span></p><p><span style="font-family: 'Ariel'"><span style="font-size: 12px">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. </span></span></p><p><span style="font-family: 'Ariel'"><span style="font-size: 12px"></span></span></p><ol> <li data-xf-list-type="ol"><span style="font-family: 'Ariel'"><span style="font-size: 12px">Language didn't get in the way of the programmer. He could do just about anything by using the proper C construct. </span></span></li> <li data-xf-list-type="ol"><span style="font-family: 'Ariel'"><span style="font-size: 12px">Portable C compiler was widely available. Consequently, people could attach a C compiler for their machine easily and with little expense.</span></span></li> </ol><p></p><p><span style="font-family: 'Ariel'"><span style="font-size: 12px">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++.</span></span></p><p><span style="font-family: 'Ariel'"><span style="font-size: 12px"></span></span></p><p><span style="font-family: 'Ariel'"><span style="font-size: 12px"></span></span></p><p><span style="font-family: 'Ariel'"><span style="font-size: 12px">One of the newest languages, C# and Java, is based on C++. Java was</span></span></p><p><span style="font-family: 'Ariel'"><span style="font-size: 12px">designed to be "C++ with the bugs fixed." </span></span></p><p><span style="font-family: 'Ariel'"><span style="font-size: 12px"></span></span></p><p><span style="font-family: 'Ariel'"><span style="font-size: 12px"></span></span></p><p><span style="font-family: 'Ariel'"><span style="font-size: 12px">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.</span></span></p><p><span style="font-family: 'Ariel'"><span style="font-size: 12px"></span></span></p><p><span style="font-family: 'Ariel'"><span style="font-size: 12px"></span></span></p><p><span style="font-family: 'Ariel'"><span style="font-size: 12px">Computer programs consist of two main parts: data and instructions.</span></span></p><p><span style="font-family: 'Ariel'"><span style="font-size: 12px"></span></span></p><p><span style="font-family: 'Ariel'"><span style="font-size: 12px"></span></span></p><p><span style="font-family: 'Ariel'"><span style="font-size: 12px">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.</span></span></p><p><span style="font-family: 'Ariel'"><span style="font-size: 12px">The data in a computer is stored as a series of bytes. </span></span></p><p><span style="font-family: 'Ariel'"><span style="font-size: 12px"></span></span></p><p><span style="font-family: 'Ariel'"><span style="font-size: 12px">C organizes those bytes into useful data. Data declarations are used by the programmer to describe the information he is working with. </span></span></p><p><span style="font-family: 'Ariel'"><span style="font-size: 12px"></span></span></p><p><span style="font-family: 'Ariel'"><span style="font-size: 12px">For example:</span></span></p><p><span style="font-family: 'Ariel'"><span style="font-size: 12px"><span style="font-family: 'Courier New'">int total; /* This means that there will is an integer data type named as total in this program */</span></span></span></p><p><span style="font-family: 'Ariel'"><span style="font-size: 12px"></span></span></p><p><span style="font-family: 'Ariel'"><span style="font-size: 12px">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:</span></span></p><p><span style="font-family: 'Ariel'"><span style="font-size: 12px"></span></span></p><p><span style="font-family: 'Ariel'"><span style="font-size: 12px"><span style="font-family: 'Courier New'">int balance[100]; /* There are (We have stored) 100 integers in an array called balance */</span></span></span></p><p><span style="font-family: 'Ariel'"><span style="font-size: 12px"></span></span></p><p><span style="font-family: 'Ariel'"><span style="font-size: 12px">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.</span></span></p><p><span style="font-family: 'Ariel'"><span style="font-size: 12px"></span></span></p><p><span style="font-family: 'Ariel'"><span style="font-size: 12px"><span style="font-family: 'Courier New'">struct rectangle </span></span></span></p><p><span style="font-family: 'Ariel'"><span style="font-size: 12px"><span style="font-family: 'Courier New'">{</span></span></span></p><p><span style="font-family: 'Ariel'"><span style="font-size: 12px"><span style="font-family: 'Courier New'">int width; /* Integer named width */</span></span></span></p><p><span style="font-family: 'Ariel'"><span style="font-size: 12px"><span style="font-family: 'Courier New'">int height; /* integer named height which we can use to store the height of the rectangle */</span></span></span></p><p><span style="font-family: 'Ariel'"><span style="font-size: 12px"><span style="font-family: 'Courier New'">color_type color; /* Color of the rectangle */</span></span></span></p><p><span style="font-family: 'Ariel'"><span style="font-size: 12px"><span style="font-family: 'Courier New'">fill_type fill; /* Fill pattern */</span></span></span></p><p><span style="font-family: 'Ariel'"><span style="font-size: 12px"><span style="font-family: 'Courier New'">};</span></span></span></p><p><span style="font-family: 'Ariel'"><span style="font-size: 12px"></span></span></p><p><span style="font-family: 'Ariel'"><span style="font-size: 12px">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.</span></span></p><p><span style="font-family: 'Ariel'"><span style="font-size: 12px"></span></span></p><p><span style="font-family: 'Ariel'"><span style="font-size: 12px"></span></span></p><p><span style="font-family: 'Ariel'"><span style="font-size: 12px">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.</span></span></p><p><span style="font-family: 'Ariel'"><span style="font-size: 12px"></span></span></p><p><span style="font-family: 'Ariel'"><span style="font-size: 12px">C is a high-level language. It lets us write a high-level statement like:</span></span></p><p><span style="font-family: 'Ariel'"><span style="font-size: 12px"><span style="font-family: 'Courier New'">area = (base * height) / 2.0; /* <img src="/styles/default/xenforo/smilies/default/lol.gif" class="smilie" loading="lazy" alt=":lol:" title="LOL :lol:" data-shortname=":lol:" /> this is the formula to calculate the area of an triangle... (baagaya X aadaarakaya X lambha usa) */</span></span></span></p><p><span style="font-family: 'Ariel'"><span style="font-size: 12px">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.</span></span></p><p><span style="font-family: 'Ariel'"><span style="font-size: 12px"></span></span></p><p><span style="font-family: 'Ariel'"><span style="font-size: 12px"></span></span></p><p><span style="font-family: 'Ariel'"><span style="font-size: 12px">We can also use control statements to control the order of processing. Statements like the <strong>if </strong>and <strong>switch</strong> statements enable the computer to make simple decisions. Statements can be repeated over and over again by using <strong>looping</strong> statements such as <strong>while</strong> and <strong>for</strong>.</span></span></p><p><span style="font-family: 'Ariel'"><span style="font-size: 12px"></span></span></p><p><span style="font-family: 'Ariel'"><span style="font-size: 12px"></span></span></p><p><span style="font-family: 'Ariel'"><span style="font-size: 12px">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.</span></span></p><p><span style="font-family: 'Ariel'"><span style="font-size: 12px"></span></span></p><p><span style="font-family: 'Ariel'"><span style="font-size: 12px"></span></span></p><p><span style="font-family: 'Ariel'"><span style="font-size: 12px">C provides the program with a rich set of standard functions that perform common functions such as searching, sorting, input, and output.</span></span></p><p><span style="font-family: 'Ariel'"><span style="font-size: 12px"></span></span></p><p><span style="font-family: 'Ariel'"><span style="font-size: 12px"></span></span></p><p><span style="font-family: 'Ariel'"><span style="font-size: 12px">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.</span></span></p><p><span style="font-family: 'Ariel'"><span style="font-size: 12px"></span></span></p><p><span style="font-family: 'Ariel'"><span style="font-size: 12px"></span></span></p><p><span style="font-family: 'Ariel'"><span style="font-size: 12px">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.</span></span></p><p><span style="font-family: 'Ariel'"><span style="font-size: 12px"></span></span></p><p><span style="font-family: 'Ariel'"><span style="font-size: 12px">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. </span></span></p><p><span style="font-family: 'Ariel'"><span style="font-size: 12px"></span></span></p><p><span style="font-family: 'Ariel'"><span style="font-size: 12px"></span></span></p><p><span style="font-family: 'Ariel'"><span style="font-size: 12px">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.</span></span></p><p><span style="font-family: 'Ariel'"><span style="font-size: 12px"></span></span></p><p><span style="font-family: 'Ariel'"><span style="font-size: 12px">So is C.... <img src="/styles/default/xenforo/smilies/default/D.gif" class="smilie" loading="lazy" alt=":D" title="Big grin :D" data-shortname=":D" /></span></span></p><p><span style="font-family: 'Ariel'"><span style="font-size: 12px"></span></span></p><p><span style="font-family: 'Ariel'"><span style="font-size: 12px">References : Oualline S, <em>Practical C Programming</em> 3rd ed., O'Reily publications,</span></span></p><p><span style="font-family: 'Ariel'"><span style="font-size: 12px"> Stroustrup B, <em>The C++ Programming language </em>sp edn., AT & T Labs. </span></span></p><p><span style="font-family: 'Ariel'"><span style="font-size: 12px"></span></span></p></blockquote><p></p>
[QUOTE="x-pert, post: 638481, member: 837"] [FONT="Ariel"][SIZE="3"]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 [B][url]http://www.elakiri.com[/url][/B]," 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: [FONT="Courier New"]1010 1111 0011 0111 0111 0110 .. and so on for several hundred instructions[/FONT] 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: [FONT="Courier New"]Program Translation MOV A,47 1 010 1111 ADD A,B 0011 0111 HALT 0111 0110 .. and so on for several hundred instructions[/FONT] 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. [B]FORTRAN [/B]was designed for number crunching, [B]COBOL[/B] was for writing business reports, and [B]PASCAL[/B] 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. [LIST=1] [*]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. [/LIST] 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: [FONT="Courier New"]int total; /* This means that there will is an integer data type named as total in this program */[/FONT] 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: [FONT="Courier New"]int balance[100]; /* There are (We have stored) 100 integers in an array called balance */[/FONT] 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. [FONT="Courier New"]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 */ };[/FONT] 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: [FONT="Courier New"]area = (base * height) / 2.0; /* :lol: this is the formula to calculate the area of an triangle... (baagaya X aadaarakaya X lambha usa) */[/FONT] 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 [B]if [/B]and [B]switch[/B] statements enable the computer to make simple decisions. Statements can be repeated over and over again by using [B]looping[/B] statements such as [B]while[/B] and [B]for[/B]. 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, [I]Practical C Programming[/I] 3rd ed., O'Reily publications, Stroustrup B, [I]The C++ Programming language [/I]sp edn., AT & T Labs. [/SIZE][/FONT] [/QUOTE]
Insert quotes…
Verification
Asuwa dahayen wadi kalama keeyada?
Post reply
Top
Bottom