Introduction to C-programming
Introduction to Programming Concepts
Program
A program is a list of instructions, together with any fixed information required to carry out those instructions. This applies to computers, of course, but also to any other subject that involves fixed instructions.
Some machines are designed with one or a few fixed programs already built in. For example, a washing machine allows you to set the desired water level and temperature, pick one of perhaps four possible wash cycles, and start the action going. Of course, you also have to add detergent and the clothes to be washed, but the actions of the washing machine itself are already completely defined and cannot be changed. This washing machine, then, is dedicated to its task and cannot be reprogrammed to perform any other tasks.
Some more modern machines are partly dedicated. For example, a microwave oven today is dedicated to the task of heating whatever is placed inside it. However, it is up to the user to specify, or program, the length of time, the power level, possibly a continuation at a different power level, and perhaps a temperature probe. In a similar fashion, modern ovens can be set to simply bake or to broil, or they can be set up to delay for a preselected time, cook the food that is in them for a preselected time, and then turn off or else drop down to a minimum "keep warm" temperature. A computer, unlike washing machines, microwave ovens is a general purpose device. It is not preprogrammed to take any specific action other than to initialize itself when you turn it on. Once you've turned it on and have your command prompt or graphic desktop on the screen, you must tell the computer what to do -- it won't do anything else by itself.
Although it is always necessary to tell the computer what to do, there are many ways available to do this. Some methods are long and involved; others are quite simple and direct. This group of pages will provide an introduction to programs and programming methods. Since a computer program consists of a series of instructions for the computer to carry out, plus any necessary fixed data required to perform those instructions, the process of programming consists of defining those instructions and that data. Thus, in order to design a program for a computer, you must determine three basic elements:
- The instructions that must be performed.
- The order in which those instructions are to be performed.
- The fixed data required to perform the instructions.
At this stage, you're not even working with a computer, except possibly as a word processor so you can write your work to a disk file instead of onto a piece of paper. Either way, however, all of the early stages of computer programming are essentially paper processes. The reason for this is that you must determine, clearly and in detail, exactly what you want the computer to do before you start telling the computer to do it. Remember that the computer will carry out the instructions you give it, exactly as given. It can't tell what you wanted; it can only do what you said. Before your new program ever gets anywhere close to a computer, there are several steps you must take. These steps are:
Define the problem
Before you can tell a computer or even another person what you want to accomplish, you must know it yourself. You must be able to clearly state what the computer is to acomplish or produce as the end result of the activities it will carry out.
Define the solution
Now that you know what information the computer is to produce as its final output, you need to look at what information you have available and what information you still need, that will apply to that output. You also need to define the equations, logical procedures, or other methods you will need to use to manipulate the raw input data into becoming the final desired output.
Map the solution
The third paper step in programming is to lay out the solution in its proper sequence. Remember that the order in which actions are taken is just as important as the actions themselves. You need to organize the solution procedure into its proper sequence, taking choices and alternatives into account. Early programming languages were designed for specific kinds of tasks. Modern languages are more general-purpose. In any case, each language has its own characteristics, vocabulary, and syntax. While this page will not by any means cover all of the available programming languages, we will take a look at a number of the better-known languages.
FORTRAN
One of the earliest computer languages, FORTRAN (an acronym for FORmula TRANslator) was designed to handle mathematical operations, originally on mainframe computers. FORTRAN was unable to handle text manipulations of any sort, and could just barely place quoted text in its printed output.
Assembly Language
Assembly language is a symbolic representation of the absolute machine code of a particular processor. Therefore, each processor has its own specific assembly language, although a family of processors, such as the Intel 80x86 series, may share some or all of its assembly code.
C
First came as an experimental language called A, which was improved, corrected, and expanded until it was called B. This language in turn was improved, upgraded, and debugged and was finally called C. The C language has turned out to be quite versatile and amazingly powerful. The C language is amazingly simple, and is nevertheless capable of great things. The Unix operating system, which has been adapted to a wide range of platforms and is gaining in popularity, is written in C.
C++
When the concepts of objects and object-oriented programming were being developed, the standard C language didn't have the built-in structures to handle them. However, C was (and is) still highly useful and well worth keeping around, so a sort of extended C language was developed. This language was essentially "C and then some", or C-plus (C+). As the concepts of object-oriented programming continued to develop, C+ had to be upgraded, and became C++ These languages requires representation of Words, Numbers, and Values with Variables Variables are an important concept in computer programming. A variable is a letter or name that can store a value. When you create computer programs, you can use variables to store numbers, such as the height of a building, or words, such as a person's name. Simply put, you can use variables to represent any kind of information your program needs. You might ask, "Why use a variable when I could just use the information instead?" As the name implies, variables can change the value that they represent as the program is running. For example, you might write a program to track the number of jelly beans you have in a jar on your desk. Because candy is meant to be eaten, the number of jelly beans in the jar is likely to change over time. Rather than rewriting your program every time you get a sugar craving, you can represent the number of jelly beans with a variable that can change over time.
Storing Information in Variables
There are three steps to using a variable:
Declare the variable Tell the program the name and kind of variable you want to use.
Assign the variable Give the variable a value to hold.
Use the variable Retrieve the value held in the variable and use it in your program.
Programming concepts using C
Introduction to C
Welcome to the world of ‘C’, a programming language which is simple to learn and highly effective. As you go on exploring ‘C’ and get experience, you will find it very interesting to work with. When we learn any new language, we first study the grammar. Similarly here we will see grammar of ‘C’ and all the basic building blocks, which will help us to write powerful programs. We begin with history of ‘C’ which tells us how ‘C’ evolved.
History of ‘C’
The history of ‘C’ ranges back to the 1960’s, when a number of computer languages were being used for various purposes. COBOL was being used for commercial applications, FORTRAN for engineering & scientific application and so on.
- An international committee was set to develop a language, which can program all types of application instead of using different languages for specific purpose. This committee developed a language called 60. But ALGOL 60 was too abstract and general.
- To reduce this abstractness and generality, a new language called Combined programming Language (CPL) was developed in 1963 at Cambridge University. But CPL was hard to learn and difficult to implement, since it was extensive with many features.
- Then, Martin Richards developed Basic Combined Programming Language (BCPL) in 1967 at Cambridge University, to extract good features of CPL.But BCPL was less powerful and too specific.
- While BCPL was developed, at around the same time a language called ‘B’ was written by Ken Thompson in 1970 at AT & T’s Bell Labs, for the first Unix system on DEC PDP-7, as simplification of CPL. But ‘B’ language also was very specific.
- At last in 1972, Dennis Ritchie designed ‘C’ by taking ‘B’ and BCPL as the base. It was designed for and implemented on the Unix operating system on DEC PDP-11. Thus it is closely related with Unix operating system. BCPL ‘and ‘B’ were typeless languages while ‘C’ provides a number of data types.
Where ‘C’ stands?
- The languages like BASIC, FORTRAN, COBOL, and PASCAL are called high level languages. These languages are application specific and are used to develop applications related to particular field. They have been designed to give better programming efficiency.
- Assembly language and Machine language are called low-level languages. These are machine-oriented languages and are designed to give better machine efficiency.
- ‘C’language provides facilities of both high level programming as well as low-level programming. Hence it can be called as middle level language.
- It is not specialized to any application as different types of application can be developed using ‘C’.
- It is not hardware or system dependent. Hence portable programs can be written with’C’.
- Compliers and operating system can be written using ‘C’. Hence it can be called as ‘systems programming language’.
- In 1988 American National Standards Institute (ANSI) established a standard definition of ‘C’ known as ANCI standard or ‘ANSI C’. Most of the features of ANSI C are supported by modern compilers.
Grammar of ‘C’
- Data types.
- Constants.
- Variables.
- Keywords.
- Operands, Operators and Keywords.
Data Types
There are basically 4 data types in ‘C’.
- char – It is used to define characters. They occupy one byte.
- int - It is used to define integer numbers .They occupy 2 bytes.
- float – It is used to define floating point numbers (single precision). They occupy 4 bytes.
- Double – It is used for double precision floating point. They occupy 8 bytes.
Additional qualifiers or modifiers can be applied to these basic types to get additional ranges like


|