140 likes | 347 Vues
C Programming language. " ‘white book’ or ‘K&R’ ". C Language Programming History. UNIX developed c. 1969 -- DEC PDP-7 Assembly Language. BCPL -- a user friendly OS providing powerful development tools developed from BCPL. Assembler tedious long and error prone.
E N D
C Programming language " ‘white book’ or ‘K&R’ "
C Language Programming History • UNIX developed c. 1969 -- DEC PDP-7 Assembly Language. • BCPL -- a user friendly OS providing powerful development tools developed from BCPL. Assembler tedious long and error prone. • A new language ``B'' a second attempt. c. 1970. • A totally new language ``C'' a successor to ``B''. c. 1971. • By 1973 UNIX OS almost totally written in ``C''.
C Language Design Goals • It to be compiled using a relatively straightforward compiler. • Provide low-level access to memory. • Provide language constructs that map efficiently to machine instructions. • Require minimal run-time support. • C was therefore useful for many applications that had formerly been coded in assembly language.
C Language Characteristics • C has facilities for structured programming and allows lexical variable scope and recursion. • Parameters of C functions are always passed by value. • Pass-by-reference is achieved in C by explicitly passing pointer values. • C program source text is free-format, using semicolon as a statement terminator (not a delimiter).
More Specific Characteristics • Non-nestable function definitions, although variables may be hidden in nested blocks. • Partially weak typing; for instance, characters can be used as integers. • Array indexing as a secondary notion, defined in terms of pointer arithmetic. • Function pointers allowing for a rudimentary form of closures and runtime polymorphism.
C Program Structure A C program basically has the following form : • Preprocessor Commands • Type definitions • Function prototypes -- declare function types and variables passed to function. • Variables • Functions
C language Function • C programming must have a main() function. • A function has the form : type function_name (parameters) { local variablesC Statements }
C Language Variables • C has the following simple data types : • To declare a variable in C, do : var_type list variables;
Defining Global Variables • Global variables are defined above main() in the following way • Example : short number,sum; int bignumber,bigsum; char letter; main() { }
Printing Out and Inputting Variables • C uses formatted output. The printf function has a special formatting character (%) -- a character following this defines a certain format for a variable : %c -- characters %d -- integers %f -- floats e.g. printf(``%c %d %f'',ch,i,x); • Scanf() is the function for inputting values to a data structure: Its format is similar to printf : i.e. scanf(``%c %d %f'',&ch,&i,&x);
Using C Language Programming • C's primary use is for "system programming", including implementing operating systems and embedded system applications. • C has also been widely used to implement end-user applications. • C source code is then input to a C compiler, which then outputs finished machine or object code. • 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.