C Programmingbook

download C Programmingbook

of 3

Transcript of C Programmingbook

  • 7/30/2019 C Programmingbook

    1/3

    C programming

    Introduction:

    C is a programming Language developed in the 1970s by Dennis Ritchie, at belltelephone Labs(new it is called AT& T Lab) of U.S.A.It was an offshoot of earlier languages

    calledBCPL(Basic Combined Programming Language)Developed by Ken Thompson &B.

    It was only when Ritchie along with Briar Kernigham,Published a definitive

    description of the languages, that the computer professionals ,impressed with Cs many

    desirable features began to promote the use of the language.BCPL& B were type less

    languages whereas Provides a Variety of data types.

    C was originally written for programming under an operation system called

    UNIX.Later this UNIX OS was rewritten effectively in c Languages.

    C is a middle level languages because it companies of low level features of second

    generation languages such as addressing memory, memory locations, manipulating bits,

    allocating memory etc. At the same time, it consists of simple English keywords along with a

    rich variety of data structures stands in between High-level languages (pol-Programmed

    oriented Language)and Low Level Languages (MOL-Machine Oriented Language).So it is very

    powerful &Flexible language.

    C is a structured language because it allows compact metallization of code& data

    using functions & code blocks which allow program to be modular &manageable.

    C library: The C Compiler provides a library function of standard programmed

    functions. These functions were written by the developer of the C Compiler. Each Library

    functions is declared in a header file having an extension of.h (For eg.All input & output

    functions, for keyboard, input &output sereen,Printer Output &Disk reading or Writing are

    defined in the header file Stdio.h).This code is made Available by a # include statement

    ,Which is also called Preprocessor Directive.

    Syntax: It means the correct way or grammar of writing a command or series of

    commands ,including all the proper options &command line statements

    Semantics: It means the logical meaning of a Statement ,separate from the

    grammatical structure.

    C-Compilation : Getting ,compiling & Executing a c program involves several steps

    .Although these steps remain the same ,irrespective of the Operating system the commands

    for implementing the steps & convention for naming file may differ on different systems.

    An Operating System is a program that controls the entire operation of a computer

    System. All input &output operations are channeled through

  • 7/30/2019 C Programmingbook

    2/3

    The Operating System. The Operating System Which an inter face between the hardware

    and the user, handles the execution of user programs. Turbo c runs under the Dos.

    Step1:Once the System is ready ,the program is entered, using the Turbo C text editors this

    is known as the source program ,since it represents the original form of the program

    Step2: The source system is compiled, using the main menu option.compliation is the

    process of translating source program instructions into machine language, understandable by the

    computer .The translation is done after examining each & every instruction minutely for its

    correctness .If there are no errors ,the compilation proceeds silently and translated program ,known

    as the object code is stored on another file ,with a.Obj extension.

    Step3: In case of any errors in the syntax or semantics of the language, they are listed our&

    the complication process steps, right there.

    These error are corrected in the source program, With the help of the text edition the source

    program completed again. This process repeats till compilation is error free.

    Step4: After the program has been translated into object code, it is linked with the library

    functions which are called by the program. For e.g. the program is using the sqrt()function ,then the

    object code of this function, should be brought from the math library of the system ,& linked to the

    main program

    Step5: The Compiled &Linked program produce another file ,with an extension of

    .exewhich is an executable file.

    C Program Structure: An important aspect in C is that it has a minimal number of keywords

    32 to be precise .These keywords are listed. These keywords combined with the formal C Syntaxform the C programming Language .Many C Compilers have, however added several keywords to

    exploit the memory organization of certain preprocessors.

    Some rules which hold good for all programs written in Care as follows:

    All keywords are lower case C is case sensitive (do while is different from Do. WHILE) Key words cannot be used for any other purpose, that is they cannot be used as

    variable or function name.

    Main() is always the first function called when a program execution begins . In C language, variable must begin with a letter of an alphabet or underscore(_) The 1 st character of the variable name may be followed by a sequence of letter or

    digits (a to z or A to Z or 0 to 9)

    On must computers, the 1 st seven or eight m characters of the variable name aresignificant

    Reserved words or keywords of the language are not used as the variable name Special characters such as blank ,space, coma, period or slash etc. are not allowed

    in the variable names

    Costants: A quantity which does not change during the executionof a program is

    called a constant .This quantity can be stored at a location in the memory of the

    computer

  • 7/30/2019 C Programmingbook

    3/3

    Rules for constructing integer constant:

    a) An Integer Constant must have at least one digit.b) It must not havea decimal pointc) It could be either positive or negatived) If no signpreceres an intger constant it is assumed to be positivee) No commas or blanks are allowed within in integer constantf) The allowable range if integer constants is-32768 to +32767

    Integer constants must fall within this range because IBM compaitable micro

    computers are usually 16 bit computers which cannot support a number falling

    outside the above mentioned range.e.g :42,+782,-8000,-7605.

    Rules forConstructing float (Real ) Constant:

    Following rules must be observed while constructing real constants expressed in

    fractional form:

    a)A real constant must have at least one digit

    b) It must have a decimal point

    c) It could be either + ve or - ve.

    D)Default Sign is +ve.

    e)No commas or blanks are allowed within a real constant

    E.G +325.34,4260.0,-32.76,-48.5792

    Real constants are often called floating point constants .the real constants could

    be written in two forms .Frational form and expontional form.

    Follwing rules must be observed while constructing a real constant expressed in

    expontional form.