Monday, 26 March 2012

ABOUT "C" LANGUAGE


Paradigm(s)Imperative (procedural),structured
Appeared in1972[2]
Designed byDennis Ritchie
DeveloperOriginally:
Dennis Ritchie & Bell Labs
ANSI C: ANSI X3J11
ISO C:ISO/IEC JTC1/SC22/WG14
Stable releaseC11 (December 2011)
Typing disciplineStaticweakmanifest,nominal
Major implementationsClangGCCIntel C,MSVCTurbo CWatcom C
DialectsCycloneUnified Parallel C,Split-CCilkC*
Influenced byB (BCPLCPL), ALGOL 68,[3] AssemblyPL/I,FORTRAN
InfluencedNumerousAMPLAWK,cshC++C--C#,Objective-CBitCDGo,JavaJavaScriptLimbo,LPCPerlPHPPike,Processing
OSCross-platform (multi-platform)

History


The initial development of C occurred at AT&T Bell Labs between 1969 and 1973;[3] according to Ritchie, the most creative period occurred in 1972. 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. (Earlier instances include the Multics system (written in PL/I), and MCP (Master Control Program) for the Burroughs B5000 written in ALGOL in 1961.)

K&R C

In 1978, Brian Kernighan and Dennis Ritchie published the first edition of The C Programming Language.[8] 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[1] covers the later ANSI C standard.
K&R introduced several language features:
  • standard I/O library
  • long int data type
  • unsigned int data type
  • compound assignment operators of the form =op (such as =-) were changed to the form op= to remove the semantic ambiguity created by such constructs as i=-10, which had been interpreted as i =- 10 instead of the possibly intended i = -10
Even after the publication of the 1989 C standard, for many years K&R C was still considered the "lowest common denominator" to which C programmers restricted themselves when maximum portability was desired, since many older compilers were still in use, and because carefully written K&R C code can be legal Standard C as well.

In early versions of C, only functions that returned a non-int value needed to be declared if used before the function definition; a function used without any previous declaration was assumed to return type int, if its value was used.                                                                                                                        C Programming Notes

Notes to Accompany The C Programming Language, by Kernighan and Ritchie (``K&R'') 

Steve Summit 

The C Programming Language, or K&R as it is affectionately known, is widely praised by experienced C programmers as one of the best books on C there is. (It was also the first; it also happens to be a best-seller.) The only real criticism K&R ever receives is that it may not be the best tutorial for beginners; it seems to assume a certain amount of programming savvy and familiarity with computers. Actually, if you read it carefully, you'll find that is constantly dispensing wisdom about programming in general, from basic concepts to deep insights to impeccable commentary on imponderable topics such as programming style, at the same time it teaches the specifics of the C language. Therefore, the fundamental criticism may simply be that K&R is not suitable for those who read carelessly.
The authors are not out to save the world or to convert it to their philosophy of programming. When they say something, they say it once, without theatrics or undue emphasis. If you read the book too quickly, or skim it, or look only for specific answers to what you think you're trying to learn today, you will miss much of the excellent advice which the authors have to offer.
These notes were prepared (beginning in Spring, 1995) for the University of Washington Experimental College course in Introductory C Programming. They are meant to supplement K&R for the reader who is new to C and perhaps to programming, and who wants a slightly more detailed, less pithy presentation. I'll add insights from my own experience, in particular by pointing out those areas where people traditionally misunderstand something about C or K&R's presentation of it. I'll also call out a few of the very deep sentences, which you might overlook at first even if you're not skimming (perhaps because their significance only becomes apparent once you've begun writing bigger or more complicated programs), but which contain advice which is absolutely vital to successful real-world programming and which, if you can take it to heart early, will save you from a lot of misery out in the school of hard knocks later on.
Note that most of these notes merely amplify on the things K&R is saying; there isn't much to say that it doesn't already say, usually better. In particular, many of the things that I'll comment on in the early chapters are discussed in more detail in the later chapters; by barging in with my know-it-all comments, I'm partially destroying the authors' careful progression from an initial, slightly superficial overview to a more detailed, complete presentation. If these notes present more detail than you want to see at first, don't worry (but please do let me know); just come back to them later to see if they clear up anything you're still uncertain on. (Also, if you find the description in K&R adequately clear, you don't have to read all of these notes, but do take note of the highlighted ``deep sentences.'')

Uses

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.[11] Some reasons for choosing C over interpreted languages are its speed, stability, and near-universal availability.[12]
One consequence of C's wide availability 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 LibraryMathematica andMATLAB 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 BitCC++COBOLEiffelGambitGHCModula-3Squeak, and Vala.[13] 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--.
C has also been widely used to implement end-user applications, but much of that development has shifted to newer languages.
C (pronounced as "see", like the letter C) is a general-purpose computer programming languagedeveloped between 1969 and 1973 by Dennis Ritchie at the Bell Telephone Laboratories for use with the Unix operating system.[4]
Although C was designed for implementing system software,[5] it is also widely used for developing portable application software.
C is one of the most widely used programming languages of all time[6][7] and there are very fewcomputer 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.


Programming in C

Introduction
A Programing Language should be designed to support certain kind of data, such as numbers,characters,strings etc. To get useful output known as information. A program is a set of statements for a specific task, which will be executed in a sequential form. These statements/instructions are formed using certain words and symbols according to the rules known as syntax rules or grammar of the language. Every program must follow accurately the syntax rules supported by the language.


The C Character set
The characters used to form words,numbers and expressions depend upon the computer on which the program runs. The Characters in C are classified in to four categories.

1. Letters-------------> Ex: A to Z and a to z

2. Digits--------------> Ex: All decimal digits 0 to 9

3. White spaces--------> Ex: Blank space, Horizontal tab, Vertical tab, New line, Form feed

4. Special characters--> Ex:, . ; " ' ! | / \ ~ _ $ ? & ^ * - + < > ( ) [ ] { } % # = @


The C Keywords
The C keywords are reserved words by the compiler. All the C keywords have been assigned fixed meaning. The Keywords cannot be used as variable names because they have been assigned fixed jobs. However, few C compilers allow to construct variable names, which exactly coincides with the keywords. It is suggested not to mix up keywords with variable names.
Keywords:

auto-----break-----case----char----const----continue----default----do

double----else-----enum-----extern-------float--------for-----goto----if
int----long----register---return---short---signed----sizeof---static
struct----switch----typedef----union---unsigned---void---volatile----while

In addition to these standard keywords some more like asm,typeof,huge,interrupt,near,etc.

Identifiers
Identifiers are names of variables,functions, and arrays. They are user-defined names, consisting of sequence of letters and digits, with the letters as the first character. Lower case letters are preferred. However, the upper case letters are also permitted. The (_) under score symbol can be used as an identifier.

Examples:1. #define N 10 2. # define a 15

Here 'N' and 'a' are user-defined identifiers

Constants
The Constants in C are applicable to the values, which do not change during the execution of a program. There are several types of constants in C. They are

1. Numeric Constants

2. Character Constants

Numeric Constants
Numeric Constants Classifieds into several categories.They are

* Integer constants
These are the sequence of numbers from 0 to 9 without decimal points or fractional part or any other symbols. It requires minimum two bytes and maximum four bytes. Integer constants could either be positive or negative or maybe zero. The number without a sign is assumed as positive.

Example: 50,70,+80,-15 etc.

* Real constants
Real constants often as floating point constants. Integer constants are unfit to represent many quantities. Many parameters or quantities are defined not only in integers but also in real numbers. For example length, height, prize, distance etc. are measured in real numbers.

Example: 1.0,2.3450,3.14 etc.

The real constants can be written in exponential notation,which contains a fractional part and an exponential part. For example, the value 2456.123 can be written as 2.4561Xe+3.

The General format of the real number contains mantissa and an exponent. The mantissa is either a real number represented in decimal or an integer.The exponent is an integer number which may be positive or nagative. The letter 'e' separating the mantissa and exponent can be written in lower case or upper case.

Character Constants
* Single character constants:

A characteer constant is a single character. They are also represented with a single digit or a single special symbol or white space enclosed within a pair of single quote marks.

Example: 'a','d','m',etc.

* String constants:

String constants are sequence of characters enclosed within a double quote 


marks. The string may be a combination of all kinds of symbols.


Example: "Hello","Sample","Ramana" etc.

Variables
A variable is a data name used for storing a data value. A variable is a name which is used for storing some value in it. Its value may be changed during the program execution of a program. A variable name may be declared based on the meaning of the operation.

Example: height,weight, average, sum, mul etc.

Rules for defining variables
1. They must begin with a character without spaces but underscore is permitted.

2. The length of the variable varies from compiler to compiler. Generally most of the compilers support 8 characters excluding extension. However, the ANSI standard recognizes the maximum length of a variable upto 31 characters.

3. The variable should not be a C keyword.

4. The variable names may be a combination of upper and lower characters. For example Sum and sum are not the same.

5. The variable name should not start with a digit.

Data Types
All C compilers support a variety of data types. This enables the programmer to select the appropriate data type as per the need of the application. Which type of data is storing in a variable is known as data type. Generally data is represented using numbers or characters. The numbers may be integers or real.

A C language programmer has to tell the system before-hand, the type of numbers or characters he is using in his program. These are data types. There are many data types in C language. A C programmer has to use appropriate data type as per his requirement.

C language data types can be broadly classified as

* Primary data type

* Derived data type

* User-defined data type

All C Compilers accept the following fundamental data types

1. Integer -------------------------------------> int

2. Character ----------------------------------> char

3. Floating Point ------------------------------> float

4. Double precision floating point------------> double

5. Void ---------------------------------------> void

The size and range of each data type is given in the below

* char -----------------------------------> -128 to 127

* int -----------------------------------> -32768 to +32767

* float ---------------------------------->3.4 e-38 to 3.4 e+38

* double --------------------------------> 1.7 e-308 to 1.7 e+308

Integer Type :
Integers are whole numbers with a machine dependent range of values. A good programming language as to support the programmer by giving a control on a range of numbers and storage space. C has 3 classes of integer storage namely short int, int and long int. All of these data types have signed and unsigned forms. A short int requires half the space than normal integer values. Unsigned numbers are always positive and consume all the bits for the magnitude of the number. The long and unsigned integers are used to declare a longer range of values.

Floating Point Types :
Floating point number represents a real number with 6 digits precision. Floating point numbers are denoted by the keyword float. When the accuracy of the floating point number is insufficient, we can use the double to define the number. The double is same as float but with longer precision. To extend the precision further we can use long double which consumes 80 bits of memory spaces.

Void Type :
Using void data type, we can specify the type of a function. It is a good practice to avoid functions that does not return any values to the calling function.

Character Type :
A single character can be defined as a defined as a character type of data. Characters are usually stored in 8 bits of internal storage. The qualifier signed or unsigned can be explicitly applied to char. While unsigned characters have values between 0 and 255, signed characters have values from –128 to 127.

Data types and their control strings

Data Type------------------->Size(bytes)--------->Range---------------------------->Control String

Char................................................ 1 ............................... -128 to 127............................................... %c

Unsigned Char............................... 1 ............................... 0 to 255...................................................... %c

Short or int................................... 2 ............................. -32,768 to 32,767 .................................... %i or %d

Unsigned int ................................. 2 .................................. 0 to 655355............................................... %u

Long................................................ 4 ................................. -2147483648 to 2147483647.................. %ld

Unsigned long............................... 4 ..................................... 0 to 4294967295................................. %lu

Float............................................... 4 .................................... 3.4e-38 to 3.4e+38.................. %f or %g

Double.............................................. 8 ................................... 1.7e-308 to 1.7e+308.......................... %lf

Long Double......................................... 10 .......................... 3.4e-4932 to 1.1e+4932.................. %lf


No comments:

Post a Comment

  ట్రావెన్ కోర్ మహారాజా   ఆయిల్యం తిరునాళ్ రామవర్మ IV  : ఆయిల్యం తిరునాళ్ రామవర్మ 1860 నుండి 1880 వరకు భారతదేశంలోని ట్రావెన్‌కోర్ సంస్థానా...