Tuesday, 18 December 2012

Data Type 'int'




  • Data :-
              The values given to the program to perform various operations on it, is referred to as data.

  • Data Type 'int' :
                  The 'int' stands for integer. An integer is a whole number without decimal part. It may have a positive or a negative value. The numbers 0, 1, 2, 3, ...., and their negatives -1, -2, -3, ....., are example of integers.
                               The 'int' data type is used to store whole values. It takes 2 bytes in memory. The 'int' type variables can store values from  -32768 to 32767 (-215 to 215 -1). If a  value greater then 32767 is assigned to an 'int' type variable then correct value will not be assigned (or fit) in the memory allocated to that variable. This condition is called integer overflow. When overflow occurs, the program continues to run but it produces incorrect result.

Saturday, 4 August 2012

Data Types in C



  • Data:-
                  The values given to the program to perform various operations on it, is referred to as data.

  • Types of Data in C:-

                          The data type defines the set of values and a set of operations that can be performed on those values. The data is given to the program as input. The data is processed according to the program instructions and output is returned.
                                 In program designing, the data and its types are defined before designing the actual program used to process the data. The values or data used in a program may be of different types. In a C program, each variable is associated with a specific data type.
                       C language provides standard data types. A standard data type is one of that is predefined in the language.

  • For Example:-

  1. int
  2. float
  3. double
  4. char
C language also allows the user to define its own data types known as user defined data types.

Types of Identifiers



  • Types of Identifiers:-
                 There are two types of Identifiers in C. These are:
  1. Standard Identifier
  2. User defined Identifier

  • Standard Identifier:-
                          Like keywords, there are also predefined identifiers in C. The predefined identifiers of the C language that are used for special purposes in the source program are called the standard Identifier. Each identifier has special meanings in C. The names used for standard library functions are standard identifiers.
  • For Example:-
                  In C program, the scanf() and printf() functions are mostly used for input or output operations. Therefore, the functions names ''scanf'' or "printf" are examples of standard identifiers.
  • User Defined Identifiers:-
                         The user (or programmer) can define its own identifiers in the C program such as variables, user defined functions, labels etc. The Identifiers defined by the user in the program are called user defined IdentifiersC is a case sensitive language. 
  • For Example:-
                    The C compiler considers 'Area' and 'area' as two different identifiers.

Wednesday, 1 August 2012

Identifier



  • Identifier:-
                     The unique names used in the program to represent the variables, constants, functions and labels etc. are called Identifiers. You can use any number of characters for the name of an identifier but only the first 31 characters are significant to the C compiler. 

  • Types of Identifiers:-
              There are two types of identifiers in C. These are:

  1. Standard Identifier
  2. User-Defined Identifier

Token


  • Token:-
               In C-language, a source program consists of keywords, variables (or identifiers), constants, operators, punctuators etc. These elements of a program known as tokens.

  • For Example:-
                    main()
                    {
                          float temp, xy4;
                          xy4 = 10;
                          temp = xy4 + 10 * 2;
                    }


                 In the above program;

  1. ''main'' is a special identifier and temp, xy4 are variables.
  2. ''float'' is a keyword.
  3. The punctuators are; { , " , '' , ( , ) , ; , white spaces etc.
  4. The operators are : , = , *  , + , etc.

Keywords of C language


  • Keyword:-
            The predefined words of the C-language that are used for special purposes in the source program are called keywords. Keywords are also known as reserved words. 
  • For Example:-
  keyword "int" is used to define the integer type variables.


                Each keyword has certain meanings in C language. They cannot be redefined or used in other ways. They cannot be used as variable or function names. Keywords are always written in lowercase's. There are 32 keywords in C.
    The ''main'' is not the keyword. It is a special identifier that indicates the beginning of the program.

  • C LANGUAGE KEYWORDS:-



Tuesday, 31 July 2012

Character Set of C


  • Character Set of C:-
                              Every programming language has its own set of characters which are used to write the statements of the program (source code). In C language also, a program is written by using a set of characters. These characters are known as alphabet or character set of C. The alphabet of C language is given below.
  1. Lowercase letters: a, b, c, ........, z
  2. Uppercase letters: A, B, C, ............, Z
  3. Digits: 0, 1, 2, ............, 9
  4. Special characters: +, -, /, =, (, ), [, ], {, }, <, >, ', ", !, @, #, $, %, \, /, ;
  5. White Spaces: blanks, new line, tab etc.

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;

    Monday, 21 May 2012

    Types of Errors

                     There are three types of errors that may occur while developing or writing C program. There errors are:

    1. Syntax Errors
    2. Logical Errors
    3. Runtime Errors

    • Syntax Errors:-

                        The set of rules (grammatical rules) of a programming language for writing statements of the computer program is known as syntax of the language. The program statements are written strictly according to these rules.
                        Syntax error occur when syntax of a programming language are not followed in writing the source code. The compiler detects these errors at compiling time of source code. The compiler reports a proper error message about the error.
                        The compiler does not compile a program that contain syntax errors. The syntax errors are easy to detect and remove.
        In C program, there can be many causes of syntax errors. Some examples are given below:-

    • Missing semicolon ( ; ) at the end of statement.
    • Missing any of delimiters  i.e { or }
    • Incorrect spelling of any keyword.
    • Using variable without declaration etc.



    • Logical Errors:-
                                                                
                       The errors in the logic of the program are called logical error. The compiler cannot detect logical errors. A program with logical errors is compiled (translated) and run successfully but it does not give correct result.


    • The sequence of instructions used in a program may be incorrect.
    • The mathematical formulas used in program instructions may be incorrect etc.
    The logical errors are difficult to detect. Logical errors can only be detected by examining all the units of the program one by one. It is a very time consuming and lengthy process.

    • Runtime Errors:-


     
                         The errors that occur during the execution of program are called the runtime errors. These types of errors may occur due to the following reasons.
    • When the program attempts to perform an illegal operation such as dividing a number by zero.
    • If input data given to the program is not in a correct format or input data file is not found in the specified path.
    • If hardware problem occurs such as hard disk error, or disk full or printer error etc.
    When a runtime error occurs, the computer stops the execution of program and displays an error message.

    Sunday, 20 May 2012

    Bugs and Debugging

    • Bugs:-

           
                     Different errors may occur in the program. These errors in the program are called Bugs.

    • Debugging:-

           The process of finding and removing bugs (or errors) in a program is known as debugging.

    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.

    Compiling C Program


    Dear readers,
           In this lesson we tell you how to compile C Program ?....
    SO FRIENDS LETS START LEARNING
    • Compiling C Program :-
                      You write the source code of the program by following rules of the programming language (i.e. C language).

         
     The source Code is not understandable by the computer. The source code must be translated into machine code before running on the computer. The process of translating source code into machine code is called compiling.
           The C compiler is used to translate the C program source code into the machine code. The translated code is called object code.
     when C compiler translates the source code, a new file created for object code with extension "obj". The first part of the name of object file is same as that of source file. 
    For Example :-
               If source file name is "test.c", then object file name will be "test.obj".
                                 To complete the C program source code into object code in Turbo C IDE, follow these steps.
    • Press Shortcut Alt+F9
    •                  OR
    • Select Compile command from compile of menu bar.
    If there is no error in the source code, it will be translated to object code successfully. If there are errors in the source code, compiler will not compile the source code and will report about the errors in the source code. All errors must be removed from the source code before creating the object code of the source code. 

    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.

    Installing Turbo C


    Dear Members,
              In this lesson we tell you How to install Turbo C Editor? and setting up directories ...
    SO FRIENDS LETS START OUR LESSON
    •  Installing Turbo C :-
                              Turbo C compiler is commonly available on CD's. When you install the Turbo C compiler, the TC directory is created on the hard disk and various sub directories such as INCLUDE, and LIB etc. are created under TC.
                        INCLUDE :-         Contains the header files of C.
                             LIB :-                 Contains the library files of C.

                         When Turbo C is installed, the above mentioned directory structure is automatically created and their respective files are copied into them.
               The installing process of Turbo C is very easy. It provides "install" program used to install the Turbo C compiler. Simply, run the install program and follow the instructions such as ; the directory name and path where you want to install the system (Turbo C compiler). By default, directory name is TC on the root of drive C.
    • Setting Up Directories :-
    By default, the source files, object files and executable files are stored in the current directory (or TC directory). You can set specific directory paths to store source files and output files (i.e. object and executable files).

                 To set the directory path, follow these steps.
    • Select "Directories" from "options" menu of Turbo C editor, a window will appear as shown below.
     
    •                       Set the path of header files in the "include Directories" field such as " C:\TC\INCLUDE". 
    •                       Set the path of library files in the "Library Directories" field such as " C:\TC\LIB ".
    • In "Output Directory", the compiler stores the object files and linker stores the 'exe' files. Set the path for output files.
    • In "Source Directories", the source files are stored. Set the path for source files.

    Sunday, 12 February 2012

    Turbo C Interface


    Dear Visitors,
            In this post we give you knowledge about Turbo C Editor. Please note that Turbo C is a most common C language compiler. This lesson helps you to know about its interface its using and its functions....
    SO FRIENDS LETS START OUR LESSON
    • Turbo C Editor :-
                               The interface of Turbo C is very simple. When IDE screen appears, the menu bar is activated. It contains various menus such as:
    • File :-
                           This menu contains group of commands used for saving program, operating existing program, printing source code of program, exiting from Turbo C editor etc.
    • Edit :-
                           This menu contains group of commands used for editing C program source code. The important editing commands are:-
    Copy, Cut, Paste, Undo etc.
    • Search :-
                           This menu contains group of commands used for searching specific word as well as replacing it with another one.
    • Run :-
                          This menu contains group of commands used for running C program.
    • Compile :-
                          This menu contains group of commands used for compiling C program. 
    • Debug :-
                            This menu contains group of commands used for debugging C program.
    • Project :-
                             This menu contains group of commands used for opening, closing and creating projects.
    • Options :-
                              This menu contains group of commands used for configuring IDE of Turbo C and setting up directories etc.
    • Windows :-
                               This menu contains group of commands used for opening, closing various windows of IDE.
    • Help :-
                                This menu is used to get help about specific topic of C language, You can also get help by pressing  F1 key. Similarly to get help about a specific keyword or identifier of C, type a word, keep cursor on the word and press keyboard shortcut Ctrl + F1.

    Friday, 10 February 2012

    TC Editor


    Dear Members,
                     In this post you will learn about TC Editor and its uses...
    SO FRIENDS LETS START LESSON
    • TC Editor :-
    In addition to a compiler, Turbo C or TC provides a complete IDE to create, edit, save, compile and run C programs. It is called the TC Editor. The C compiler is linked with TC Editor. This type of editor is also called linkage editor.
                         TC editor also provides a powerful debugging feature. This means that it helps to detect and remove errors in the C program.
                                  Once Turbo C compiler is installed. It is very easy to write,compile and execute C programs, Turbo C editor has an executable file "TC.EXE". By default, it is in "TC" directory in C drive. When the file is executed, the IDE of Turbo C editor is displayed on the screen along with development tools.
                   To load Turbo C editor, follows these steps :-
    • Go to DOS prompt. By default, it will appear as:

    C:\Windows>
    • Change the directory to TC by applying command;

    C:\Windows> CD\TC  [press Enter Key]
    • Type TC and press Enter Key. The turbo C editor is started and IDE appears on the screen as shown below.
    Note :-
                 Today, in most computers Turbo C++ compiler is installed. If Turbo C++ compiler is installed in your computer, then the path of TC.EXE is: 
    C:\TC\BIN

    Thursday, 9 February 2012

    C compiler & IDE


    Dear Members,
           In this post we will tell you about the Compiler of C Language and its importance also tell you about IDE...
    SO FRIENDS LETS START OUR LESSON
    • Compiler of C Language :-
    Every High Level language has its own translator program. It is used to translate the source code into machine code. C language also has its own translator program called C compiler.
     You must install C compiler into your Computer for compiling the C program. Many C compilers are available. The Most popular and commonly used C compiler is Turbo C.
    Note :-
             "You can also translate C program with C++ compiler."
    • IDE :-
     

    IDE
    stands for Integrated Development Environment. The environment in which a computer program is written, compiled, executed, tested and debugged is called Integrated Development Environment.

    C Program Errors


    Dear Members,
             "Today we share with you an important lesson"
    In this lesson we tell you about those errors which can be made by every beginner programmer at that time when they write C program. 
               In this post we tell you that what happen if you made these mistakes during writing C program
    SO FRIENDS LETS START LESSON
    • ERROR No 1).
    • Leave  #include<stdio.h> :-

                                      #include<stdio.h>

                               int main(void)
    {
                                                                                printf("My first Program in C");
    }
                       A header file must be included at the beginning of the program. If its functions are to be used in the program. In the above program, the printf() function is used to print the message. It is part of header file "stdio.h". When you leave out the #include<stdio.h> line from the program given above, the C compiler displays an error message as shown below:
    ''Function 'printf' should have a prototype''
    • ERROR No 2).
    • Leave Semicolon :-
     
    Each statement in C ends with a semicolon (;). If you leave out the semicolon at the end of the printf() statement, an error message occurs as shown below.
    Statement Missing ;

                 Hope this lesson is really helpful for you. If you like this lesson don't forget to make a comment on it.
    Thanks for your time.

    C program Statements


    Dear Members,
            Today we will discuss about C program statements and also give you some examples....
    SO FRIEND LETS START OUR LESSON
    • C program Statements:-
    A program statement is a fundamental unit of any programming language. It is an instruction for the computer to do something. The set of statements of C program are written under the main() function (or any user defined function) between curly brackets i.e {     }. Typically, in C program, the library functions are called for execution in the main body of the program.
    For Example:-
                        The printf() function is used to print a message or output of the program. Every statement of C program must be terminated with semicolon (;). It is called statement terminator. If statement terminator (;) is missing at the end of any statement, then the following error message will be reported by C compiler during compiling process.
    Statement Missing
             C language is a case sensitive language. Each statement of C program is normally written in lowercase letters. However, variable names or user-defined function names with uppercase letters can be used in C program.
                                 C program is written below to clear the computer screen and to print a message on the screen.
                                       #include<stdio.h>
                                        #include<conio.h>
                main()
    {
                                  clrscr();
                                                           printf("Welcome");
    }

    In the above program, two statements are written in the body of main() function. Each statement ends with semicolon ( ; ).