Home | » | C Programming | » | Introduction to C Programming |
As a Programming Language, C is rather like Pascal or Fortran. Values are stored in variables. Programs are structured by defining ad calling functions. Program flow is controlled using loops, if statements and functions calls, Input and Output can be directed to the terminal or to files. Related data can be stored together in arrays or strctures.
Contents
- Brief Introduction
- Evolution of C
- Features of C-Language
- Types of C
- Character set
- Keywords and identifier
- C-tokens
- Constants and variables
- Loading,saving and comiling a C-Program
- Data Types
- Declaration of Variable or Data Type Declaration Statement
- Assigning name to variable
- C delimeters
Brief Introduction
C is a general purpose structured powerful modern language. It is a High Level scientific language as well as business oriented language. This language also has low level programming features. This language was designed for developing fast, reliable, efficent, economical and portable system software and application software (programs). Till the development of c, no language was simple and fully featured to fulfill all types of requirements, some language was powerful but very complex and some was simple but not very powerful. But C fulfilled both the things i.e. simplicity and power to do versatile jobs.
Evolution of CMany of its principles and ides were taken from the earlier language B and B's earlier ancestors BCPL and CPL. CPL (Combined Programming Language) was develople with the purpose of creating a language that was capable of both high level, machine independent programming and would still allow the programmer to control the behaviour of individual bits of information.
The original name of B-LANGUAGE is BCPL (Here BCPL stands for Basic Combined Programming Language and it is a preliminary language of C). Afterwards the BCPL was renamed called B-LANGUAGE from its first alphabet. This language has number of advance features than BCPL.
From 1972(some researcher say 1970) at BELL-LABORATORIES (which is the part of AT & T) in U.S.A by the scientist Dennis Ritche developed a powerful software tool which has a big facility called C-LANGUAGE. C-LANGUAGE was renamed from the BCPL's second alphabet.
After many years research, C language was developed and become popular. C-LANGUAGE has different versions from time to time. First version fo C-LANGUAGE is 1.0 that has high-level language compilation facility in two phases. Afterwards in 1975 C-LANGUAGE 2.0 was developed which has both high level and low level facility. UNIX(which is multi-user operating system) operating system was written in C-LANGUAGE by Ken Thomson. Later on in 1980, an IDE(Integrated Developed Environment) a menu driven with compilation and debugging facility, and advanced version of C-LANGUAGE was developed which is called version 4.0.
Afterwards around 1983 an object oriented programming (OOP) software was developed from the C-LANGUAGE that is called C++. Between 1983 and 1986, Bjarne Sroustrup of Bell Labs began working on an extension to C, called C++. The main additions of C++ were classes and object oriented code, meaning that C code could be much more easily reused and ported. This is the language that most modern day programmers use.
C's power and flexibility soon became apparent. Because of this, the Unix opreating system which was originally wriiten in assembly language, was almost immediately re-written in C in 1975. During the rest of the 1970's, C spread throughout many colleges and universities because of it's close ties to Unix and the availability of C compilers. Soon, many different organizations began using their own versions of C causing compatibility problems. In response to this in 1983, the American National Standards Institue (ANSI) formed a committe to establish a standard definition of C which became known as ANSI Standard C. Today C is in widespread use with a rich standard library of functions.
Featured of C-language:
C-Language has number of characteristics or features. Due to this C-Language becomes popular among the scientists for development of scientific software, as an entertainment for developing the games package and among businessman for the development of business application oriented tools.
So C-Language has number of properties which are explained as :
- C-Language is rich in built-in function or standard functions (library function).
- C-Programmers are very efficient and have fast execution speed.
- C-Language has more data types than others languages.
- C-Language has 40 keywords (reserve words) among which 32 are standard keywords which are used in daily routine programming. Eight keywords are optional which are used in low level programming.
- C-Language has more operators than other language.
- C-Language programs are highly portable.
- In C-Language you can take 0 to 15000 variables in a single program depending on of variable is enough as compared to the other language
- C-Language is a Structured Programming language. Sturcture programming means it has different modules and blocks like, if block, do block, for block, switch module etc.
- C-Language is very simple to learn and use.
- C-Language is used to develop graphics software by using graphics programming.
- C-Language is also called middle level langugae because it has both types of features. i.e. High Level as well as Low Level.
Types of C
C is mainly of Two types.
(i) Turbo C or Common C:
Until recently there was on dominant form of the C Language. This was the native UNIX form, which for historical reasons is known as either Bell Labs C, after the most popular compiler, or K.&R. C, after the authors of the most popular textbook on ther language. It is now oftern called "Classic C". We can also called by nickname "TC".
(ii) ANSI C:
The American National Standards institute defined a standard for C, eliminating much uncertainty about the exact syntax of the language. This newcomer, called ANSI C, proclaims itself the standard version of the language. As such it will inevitably overtake, and eventually replace common C.
Character Set:
Character Set Means that the characters and symbols that a C Program can understand and accept. These are grouped to form the commands, expressions, words, c-statements and other tokens for C language. Character Set is the combination of alphabet or character, digit, special characters and white spaces. More about a C-program we can say that it is a sequence of characters. These caracter from the character set play the different role in different way in the C-compiler.
There are mainly four categories of the character set as shown below:
- Letter or Alphabet
In the character set, character or alphabet are represented by A-Z or a-z. C-Language is case sensitive so it takes different meaning for small and upper case letters, By using this charater set C-Statements and character constands can be written very easily. there are total 26 letters used in C-programming.
- Digit
In the character set digit are represented by 0-9 or by combination of these digits. By using the digits numeric constant can be written easily. There are total 10 digits used in C-programming.
- Special Characters
There are total 30 special characters used in the C-programming. Special characters are used for C-statements like to create an arithmetic statement +,-,* etc., to create logical statement <,>,<=,>=,== etc are required. All the characters with the meanings are discussed in the table below:
Special Character Meaning , Comma . Period : Colon ; Semicolon ? Question Mark ' Single Quote " Double Quote ( Left Parenthesis ) right Parenthesis [ Left Bracket ] Right Bracket { Left Brace } Right Brace < Left Angle Bracket or less than symbol > Right Angle Bracket or greater than symbol = Equal to Sign. ! Exclamation Mark | Vertical Bar or Pipe symbol / Slash or Forward Slash \ Backslash or Backward Slash ~ Tilde symbol + Plus sign - Minus sign or Hypen sign * Asteric sign # Number sign or Hash symbol % Percentage sign ^ Caret symbol & Ampersand sign @ "At the rate" symbol _ Underscore sign - Empty space character Or White Spaces
White spaces has blank space, new line return, Horizontal tab space, carriage ctrl, Form feed etc. are all used for special purpose. Also note that Turbo-C Compiler always ignore these white space characters in both high level and low level programming.
- Identifier must be from the character set.
- The first character of an identifier should be an alphabet or a letter and shoult not be a digit or a special character or a white space.
- Identifier should not be a Reserve word or a Keyword
- Identifier are always case-sensitive in the C-programming. for example the identifier BILL, Bill and bill are three different dentifier used for different purposes.
- Note that the charcter "_" underscore from the character set should not be used as an identifier alone in the C-programming. It should be within the alphabets.
- The length of an identifier should not be long. The maximum length of an identifier in all the C-compiler be 32 character long. some compiler has maximum 8 character long length like in the ANSI-C Compiler.
- Hyphen (-) should not be used in an identifier.
- Always avoid a single character as an identifier like a,b,m, etc.
- Primary or Scalar or standard or Fundamental or simple data type
- Secondary or Derived data type or Structured data type
- User defined or Enumerated or Typedef data type
- Empty data type or void data type
- Pointer data type
Keywords and Identifiers:
C-language has some reserve words which can not be used as variables or identifiers. These reserve words are keywords of C-language. These are the part of the C-Tokens.
There are mainly 40 keywords among which 32 are used by many C-compilers(also called Standard Keywords) for high level programming, whereas remaining 8 reserve words(also called Optional Keywords) are used by the programmer for the low lever programming.
These standard keywords are :auto | extern | size of |
break | float | static |
case | foe | struct |
char | goto | switch |
constant | if | typedef |
continue | int | union |
default | long | unsigned |
do | register | void |
double | return | volatile |
else | short | while |
enum | signed | |
Also some compiler have Advanced Optional Keywords as below: | ||
ada | far | near |
asm | fortran | pascal |
entry | huge |
Identifiers are some words or names which identify whether it is a constant or variable. These are the data names used by the programmer.Identifier gives us the unique identification having unique sequence of character (from the character set) use for special purpose. Following are the some rules which should be used for the fulfillment of the identifier requirement:
C-Tokens:
As in the English language, in a paragraph all the words, punctuation mark and the blank spaces are called Tokens, Similarly in a C-Program all the C-statements having Keywords, Identifiers, Constants, Strings, Operators and the Special Symbols are called C-Tokens. A Token is an individual entity of a C-program.
Some C-Tokens used in C-program are:Reserve Words | float, do , if , for etc. |
Identifiers | pay, salary , rate etc. |
Constants | 200,15.4,-45 etc. |
String | "Laura", "2011-12", etc. |
Operators | +,*,<,>=,&& etc. |
Special Symbols | (),{},#,@ etc. |
Constants and variables:
Constant:
In a C-program, when you either enter the data for input or assign the data to some identifier, then there be need of some stroage space, so that entered or assigned data can be processed in a meaningful way. So the processed data be stroed in two forms by the C-program. These two forms or categories are called Constant or Variable.
Constant uses the secondary storage area. Contstants are those quantities whose value does not vary during the execution of the program i.e. value is fixed.
In C-Language constants are mainly of two types:
I. Numeric constant II. Non-numeric or Character Constant
There are further sub-divided into more categories as shown below:
Variables:
In C, a variables must be declared before it can be used. Variables can be declared at the start of any block of code, but most are found at the start of each function. Most local variables are created when the function is called, and are destroyed on return from that function. Variables uses the primary storage area. Variables are those quantities whose value can vary during the execution of the program.
A declaration begins with the type, followed by the name of one or more variables. For example,Loading,saving and comiling a C-Program:
Before entering the program into the computer, C compiler should be loaded into the computer's main memory(RAM).
A Turbo-c compiler can be loaded by typing TC at DOS prompt in the sub-directory where Turbo-C compiler has been stored on the hard disk. For example suppose you have Turbo-C Compiler in the "TurboC" directory in the C drive, then how to open c follow below step:
First of all open command prompt from start button and then choose run and type cmd or commandC-Data Types:
C-language becomes powerful with the help of number of data types linked with it. Data types vary according to their use. Different compilers have different data types. Actually variables type depends on the data types. Data type is the description of nature of data either in numeric forms (integer or real) or in character form(single character or string).
There are mainly five types of data types used in the Turbo-C compiler(four in the ANSI-C compiler).Primary Data Type:
The fundametal data types are explained in details as:
a) Integer Data Type:
b) Real (float) Data Type:
c) Double Data Type:
d) Character Data Type:
Structured Data Type or Derived Data Type:
Derived data types are derived from scalar data type by adding some additional relationship with the elements of the primary or sclar data types. Note that derived data type may be used for representing a single value or multiple values. As these data type have different structure depending on the C-coding, these are also called Structured data type. These are also called secondary data type. These are further sub divided into three categoires :
a) Arrays and Strings
b) Structures
c) Unions
User defined data type or Enumerated Data Type:
This is also used for type definition, i.e. it allows the users to define a variabl or an identifier, which is used for representation of existing data type. In other words, it provides us a way to define our own data type and also can define the value of a variabl or an identifier stores into the main memory.There are two types of User-defined data types. These are Enumerated and typedef data type. Euumerated data type can be defined as:
or
eumu identifier {v1,v2,v3,...............vn} variable;
or
eumu month{Jan,Feb,Mar,...............Dec} m;
Also there is another user-defined data type typedef. This is used to represent the existing data type. Typedef data type can be defined as :
typedef data-type identifier;
Here data-type may be int,float, double and char. Identifier gives us the information of new name given to the data type. For examples.
typedef int year;
typedef float year;
Void or Empty Data Type:
Void or empty data type is used in the user-defined function or user defined sub-programs. These are used when the function sub-program returns nothing. Also it is used when a function or any sub-program have not any argument in it.
Pointer Data Type:
Pointer data types are used to handle the data at their memory addresses.
Declaration of Variable or Data Type Declaration:
As you know a variable can be either of integer type or float or character type. So to declare a variable having type for identification. The date type declaration statement has the general syntax as :
Where v1,v2,.....vn are variables and data type may be either float, int or char. Some valid data type declaration statement are as follow :
int a,b,c;
float x,y,z;
char name[10],city[10][20];
1.11 Assigning name to variable:
We can assign a value to a variable by using assignement statement as :
variable = constant;
or
variable = expression;
or
data type variable = constant;
For example below are some valid assignment statements :
sum = 0;
i = 1;
int a = 10;
char x='b';
C Delimeters:
In the C Programming language, there are some special character used for special syntactic meaning and these are called C delimiters. There are five powerful C delimiters used in a C Program. These are described as :
Delimiter | Meaning |
: (colon) | Used for label entery |
() (parenthesis) | Used for expression and enclosing the arguments in the function declaration. |
[] (square bracket) | Used for describing the size for array. |
{ } (curly bracket or brace) | Used for beginning and ending of function, blocks and main program |
; (semicolon) | Used at the end of every C Statement except control statement. |
1 comments:
Click here for commentsNice post I think that this blog was really well done. The blog was fun and Max taught us many great techniques. I plan on using this knowledge for my own projects. I highly recommend this blog to anyone wanted to learn C programming
ConversionConversion EmoticonEmoticon