C (programming language)

C is a general-purpose, procedural computer programming language which is still in use more than thirty years after its creation. C was developed in 1972 by Dennis Ritchie and Brian Kernighan (then of Bell Laboratories) for use with the Unix operating system, and, before it entered the standards process, in a reference book. . The language has been implemented for many different computer platforms and eventually became standardized by ANSI and ISO. Although superceded by more modern languages for general application use, as of 2009 versions of C are still used, primarily for writing operating system software and embedded programs (for gadgets such as smart phones).

Historical influence of C
The historical influence of the C programming language should not be underestimated. At the time of its initial implementation, most or all programming tools did not allow recursive function calls. C, in conjunction with UNIX, takes advantage of two run-time memory-management strategies: the "call stack" (used by the compiler to keep track of local variables declared in functions and subroutines) and the "heap" (used explicitly by the programmer to pack arbitrary data structures into memory). The use of the stack meant that C allows functions to call themselves recursively. The use of the heap means that programmers can define arbitrarily complex data types. This led to a powerful programming paradigm which is still in use today. Although powerful, the heap also needs to have memory reclaimed explicitly by the programmer after data structures are no longer needed; this error-prone process, called "garbage collection", is one of the aspects of C programming that is difficult. Failure to correctly reclaim all no-longer-needed memory from the heap eventually results in a program running out of memory, a situation called a "memory leak". More modern languages such as Java and C# handled reclamation of no-longer-used heap space automatically, resulting generally in more reliable programs.

C's name derives from those of two of its predecessors (also worked on by the same authors at Bell Laboratories), Basic Computer Programming Language (BCPL), and a BCPL variant,B.

Syntax of the C family of programming languages
The syntax and stack-based scope behavior of C were also adopted by several later programming languages, including C++, Java, and C#. Javascript uses similar syntax but has different scope rules. The adopted characteristics tend to include case sensitivity, ending of statements with a semi-colon, use of { } to enclose blocks of code, enclosing procedure parameters inside  pairs, and allowing temporary variables to be declared inside blocks or procedures (which are semantically destroyed subsequent to that procedure's execution, and reinitialized from scratch during subsequent procedure executions).

Hello World
int main(void) { printf("Hello, world!\n"); return 0; }
 * 1) include 

Analysis of the example
The Hello World program (see above) appears in many programming languages books and articles as a cursory introduction into a language's syntax. It was introduced in the book The C Programming Language.

tells the precompiler to include the contents of the header file stdio.h, which declares standard input and output functions into the program before compiling.

tells the compiler that there is a function named  which expects no parameters  and will return an integer number to the caller. Due to a standard convention of the language,  is the first function called after the execution environment of the program has been set up. The opening curly brace following  denotes the beginning of the function.

will make the program output  and a new line  on the screen. is itself a function similar to  but predefined in a library (libc) and linked into the program at compile time or runtime. The trailing semicolon is the end of statement marker in C.

defines the value to be returned from  and leaves the function back to its caller, some standard C startup code. After some additional cleanup that code will pass the 0 on to the operating system, to which it means 'success'.

signals the end of the function definition to the compiler.

Pros

 * Although C programs can either be compiled or run through an interpreter, most are compiled and run as native code. Compiled C programs tend to run faster than languages requiring a runtime or interpreter.


 * C is low-level enough to take advantage of hardware-specific capabilities, and thus any low=level software packages that have close interaction with hardware are written in C. For example, most of Unix is written in C. Most compilers and interpreters are written in C. C gives programmers access to hardware, enabling them to manipulate memory. This feature is advantageous but can prove problematic if misused.


 * C has been standardized, which minimizes differences across compilers, but it is still hardware-dependent. For example, the storage width of integers depends on the underlying hardware and may differ across two different hardware architectures.  C programs can be made portable across multiples systems, but only with some diligence on the part of the programmer. C compilers are available for most systems.

Cons

 * C programmers must explicitly managed how their program uses heap memory. Although allowing great flexibility, pointers (addresses of data structures in the heap) can make C code very hard to understand and debug. And forgetting to deallocated used memory after it is no longer needed will cause programs to crash after they have been running for awhile (because the heap fills up).


 * Strings in C are implemented as special data structures. Parts of the extensive string-handling libraries in C do not always enforce correct memory management practices.  Programmer errors may go undetected at compile-time and cause crashes or other problems at runtime.  Programmer errors may also make a program vulnerable to malicious exploitation of the entire computer system.  See the buffer overflow article for some examples.


 * The low level nature of C, which does not hide specific hardware architectural details, makes it relatively harder to learn than other programming languages.


 * Even with programmer diligence, it is still difficult to guarantee that a C program which runs on one type of hardware will also run identically on different hardware without modification.