RSS2.0

Looking Something??



[C Programming Language] Introduction to C Programming Language

Thursday, February 14, 2008

Introduction


C is a general-purpose, block structured, procedural, imperative computer programming language developed in 1972 by Dennis Ritchie at the Bell Telephone Laboratories for use with the Unix operating system. It has since spread to many other platforms. Although predominantly used for system software, C is used not only for system but also for applications widely. C has also greatly influenced many other popular languages, especially C++, which was designed as an enhancement to C.

Philosophy


C is an imperative (procedural) systems implementation language. Its design goals were for it to be compiled using a relatively straightforward compiler, provide low-level access to memory, provide language constructs that map efficiently to machine instructions, and require minimal run-time support. C was therefore useful for many applications that had formerly been coded in assembly language.

Despite its low-level capabilities, the language was designed to encourage machine-independent programming. A standards-compliant and portably written C program can be compiled for a very wide variety of computer platforms and operating systems with minimal change to its source code. The language has become available on a very wide range of platforms, from embedded microcontrollers to supercomputers.

Characteristics


As most imperative languages in the ALGOL tradition, C has facilities for structured programming and allows lexical variable scope and recursion, while a static type system prevents many unintended operations. Parameters of C functions are always passed by value. Pass-by-reference is achieved in C by explicitly passing pointer values. Heterogeneous aggregate data types (the struct in C) allow related data elements to be combined and manipulated as a unit. C has around 30 reserved keywords and the source text is free-format, using semicolon as a statement terminator (not a delimiter).

C also exhibits the following more specific characteristics:

  • Non-nestable function definitions, although variables may be hidden in blocks to any level of depth

  • Partially weak typing, for instance, characters can be used as integers in a way similar to assembly

  • Low-level access to computer memory via machine addresses and typed pointers

  • Function pointers allowing for a rudimentary form of closures and runtime polymorphism

  • Array indexing as a secondary notion, defined in terms of pointer arithmetic

  • A standardized C preprocessor for macro definition, source code file inclusion, conditional compilation, etc.

  • Complex functionality such as I/O and mathematical functions consistently delegated to library routines

  • Syntax divergent from ALGOL, often following the lead of C's predecessor B, for example using

    • { ... } rather than ALGOL's begin ... end

    • the equal-sign for assignment (copying), much like Fortran

    • two consecutive equal-signs to test for equality (compare to .EQ. in Fortran or the equal-sign in BASIC)

    • && and || in place of ALGOL's and and or, which

      • are syntactically distinct from the bit-wise operators & and | (B used & and | in both meanings)

      • never evaluate the right operand if the result can be determined from the left alone (short-circuit evaluation)



    • a large number of compound operators, such as +=, ++, etc.




Uses


C's primary use is 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 runtime demand on system resources.

C has also been widely used to implement end-user applications, although as applications became larger much of that development shifted to other, higher-level languages.

One consequence of C's wide acceptance and efficiency is that the compilers, libraries, and interpreters of other higher-level languages are often implemented in C.

C is used as an intermediate language by some higher-level languages. This is implemented in one of two ways, as languages which:

  • Emit C source code, and one or more other representations: machine code, object code, and/or bytecodes. Examples: some dialects of Lisp (Lush, Gambit), Haskell (Glasgow Haskell Compiler); Squeak's C-subset Slang.

  • Emit C source code only, and no other representation. Examples: Eiffel, Sather; Esterel.


C source code is then input to a C compiler, which then outputs finished machine or object code. This is done to gain portability (C compilers exist for nearly all platforms) and to avoid having to develop machine-specific code generators.

Unfortunately, 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--.

Libraries


The C programming language uses libraries as its primary method of extension. In C, a library is a set of functions contained within a single "archive" file. Each library typically has a header file, which contains the prototypes of the functions contained within the library that may be used by a program, and declarations of special data types and macro symbols used with these functions. In order for a program to use a library, it must include the library's header file, and the library must be linked with the program, which in many cases requires compiler flags (e.g., -lm, shorthand for "math library").

The most common C library is the C standard library, which is specified by the ISO and ANSI C standards and comes with every C implementation. ("Freestanding" [embedded] C implementations may provide only a subset of the standard library.) This library supports stream input and output, memory allocation, mathematics, character strings, and time values.

Another common set of C library functions are those used by applications specifically targeted for Unix and Unix-like systems, especially functions which provide an interface to the kernel. These functions are detailed in various standards such as POSIX and the Single UNIX Specification.

Since many programs have been written in C, there are a wide variety of other libraries available. Libraries are often written in C because C compilers generate efficient object code; programmers then create interfaces to the library so that the routines can be used from higher-level languages like Java, Perl, and Python.

Related languages




C has directly or indirectly influenced many later languages such as Java, C#, Perl, PHP, JavaScript, and Unix's C Shell. The most pervasive influence has been syntactical: all of the languages mentioned combine the statement and (more or less recognizably) expression syntax of C with type systems, data models and/or large-scale program structures that differ from those of C, sometimes radically.

C Compiler


Dev-C++ GUI Screenshot


Dev-C++ is a free integrated development environment (IDE) distributed under the GNU General Public License for programming in C/C++. It is bundled with the open source MinGW compiler. The IDE is written in Delphi. The latest release of Dev-C++ version is 4.9.9.2 which is launched in February 22, 2005.


The project is hosted by SourceForge. Dev-C++ was originally developed by programmer Colin Laplace. Dev-C++ runs exclusively on Microsoft Windows.

The program itself has a look-and-feel similar to that of the more widely-used Microsoft Visual Studio. One additional aspect of Dev-C++ is its use of DevPaks, packaged extensions on the programming environment with additional libraries, templates, and utilities. DevPaks often contain, but are not limited to, GUI utilities, including popular toolkits such as GTK+, wxWidgets, and FLTK. Other DevPaks include libraries for more advanced function use.

Dev-C++ can be downloaded from : http://sourceforge.net/projects/dev-cpp/

Source : en.wikipedia.org/wiki
programmingtutorial.wordpress.com

0 comments: