Showing posts with label C program. Show all posts
Showing posts with label C program. Show all posts

Tuesday, 22 May 2012

Constant Macro, Delimiters, Statement Terminator

Dear Members,
    In this lesson we give you a concept about Constant Macro, Delimiters, Statement Terminator and its importance in C program.

  • Constant Macro:-
                        The 'define' directive is an important preprocessor directive. It is used to define a constant known constant macro. A constant macro is an identifier, which is assigned a particular constant value. The value of identifier remains constant during the execution of program.

  • Delimiters:-

                            The body of the function is surrounded by braces (or curly brackets { and } ). These braces are called delimiters. The left brace indicates the start of the body of the function, whereas the matching right brace indicates the end of the body by the function.

    • Statement Terminator:-
     
                                Every statement of C program must be terminated with semicolon ( ; ). It is called statement terminator. If any of the statement is missing the statement terminator ( ; ), the following error message will be shown by compiler during compiling process.
    Statement missing;

    Sunday, 4 March 2012

    Preparation of C Program for Execution



    Dear readers,
                  In this lesson we tell you about the some necessary steps to prepare C program for execution..
    SO FRIENDS LETS START LESSON
    • Some steps which are taken to prepare a C program for execution are :-
    1. Creating & Editing C Program
    2. saving C program
    3. Compiling C program
    4. Linking C program
    5. Loading C program
    6. Executing C program
    • Creating & Executing C program :-
                                                       The first step is to create and edit the source program in C. The C program is usually and edited in Turbo C editor.
    • Saving C program :-
    After writing or editing the source program, it is saved on the disk as text file with an extension ".c".
    • Compiling C program :-
    In this step, the source program is compiled. The source program is converted into machine code. The C compiler is used to translate  the C program source code into the machine code.
    • Linking C program :-
    In this step, the Linker links object file produced by the compiler to many other library files.
     After linking the object code  to the libraries, an executable file with extension EXE is created.
    • Loading C program :-
                        In this step the loader loads the executable file from disk into memory for execution. The program must be loaded into memory for execution.

    • Executing C program :-
    In this step, the program is executed on the computer. The CPU fetches instructions of program from memory one by one and takes action on them.


    Monday, 20 February 2012

    Executing C Program


    Dear readers,
         After successfully learn the compiling C program and linking C program lessons. You are now ready to learn how to execute C program on your computer. 
    SO FRIENDS LETS START LEARNING
    • Executing C program :-
                                The process of running the program on computer is called executing. The program must be loaded into memory for execution. This work is done by the Loader. Loader is a program that loads the executable file from disk into memory.
    For Example :-
                 In Windows environment, when the name of an executable file is double clicked. The Loader loads the file into the computer memory for execution on the CPU.
    In TC Editor, you can compile and run the program by pressing the shortcut key Ctrl+F9 or by selecting Run command from Run menu of Turbo C IDE. The program is first compiled and then run on the computer.
                       When the program is run, the program's output  is printed on the screen but not to the IDE window. To see the program's output, select "User screen" command from the window menu, or press keyboard shortcut Alt + F5. You will see normal DOS screen with program output (if any).
          Some errors may occur during the execution of the program. These errors are called the execution errors. These errors may halt the system.

    Linking C Program


    Dear readers,
                   In this post you will learn the method to link a C program....
    SO FRIENDS LETS START LEARNING
    • Linking C program :-
                   Linking is a process in which the object file produced by the compiler is linked to many other library files. This work is done by the Linker.
     The Linker is a program and is a part of compiler. After linking the object code to the libraries, an executable file with extension EXE is created.
    For example :-
                If  source file name is "test.c", then executable file name will be "test.exe".
                          In Turbo C environment, program is linked as;
    • Select Link command from Compile menu on the menu bar.
     
    In Turbo C IDE, compiling and linking can be performed together in one step. To do this, select Make command from Compile manu or press F9 key. The linker can also detect errors.
    • For Example :-
    If the source code uses a library function that does bot exist, the linker generates an error. If there is any error in the source code, the Linker will not create the executable file.
     In this case, the errors are removed from the source code and source code is compiled again. The new object file is then linked to the libraries to create the executable file. The file directly dun on the computer.

    Sunday, 19 February 2012

    Creating, Editing and Saving C program

    128 x 128 black c gif icon image
    Dear Readers,
           In this lesson following topics are covered...
    • Creating C Program
    • Editing C Program
    • Saving C Program

    SO FRIENDS LETS START OUR LESSON
                   You can write, edit and save a C program in any text editor program. But Turbo C provides a complete IDE for this purpose. You can easily write, edit and save C program in TC editor.
    • Creating C Program :-

                      The process of writing a new C program by following the rules of C language is called creating a C program. To write a new C program, load the TC editor and type the source code of program.
    • Editing C Program :-
       
                        You can also make changes during writing new programs as well as in the exiting C program. Therefore, the process of writing, changing and revising the source code is called editing program.
    • Saving C Program :-
     
                            After writing or editing the source program, you should save it on the disk as text file with an extension " .c ". This process is called saving the program.
                             To save source code in TC editor, follow these steps.
    • Select Save command from file menu or press F2 key. A dialog box will appear. The default file name of source code is NONAME00.C
    •     Type the name of file such as "first.c" and press Enter key. You can also select a specific folder (or location). where you want to save the file. Turbo C editor automatically assigns the file extension as " .c "



    Note:-
                                                You can also compiler and run C program in Turbo C IDE without saving it first but it is not a good practice. You must save the program before compiling and executing it. It is because sometimes your program may be hanged during execution and your source program code may be erased from the main memory.