Data types

Integer "int" type data:

int variables can represent negative and positive integer values (whole numbers). There is a limit on the size of value that can be represented, which depends on the number of bytes of storage allocated to an int variable by the computer system and compiler being used. On a PC most compilers allocate two bytes(now in modern systems it is four bytes) for each int which gives a range of -32768 to +32767. for example:
int num; 
int n, m; 
int temp = 10; // initializing variable also.

Posted by IRFAN Saturday, April 3, 2010 0 comments

Declaration of variables

In C plus plus  (as in many other programming languages) all the variables that a program is going to use must be declared prior to use. Declaration of a variable serves two purposes:
It associates a type and an identifier (or name) with the variable. The type allows the compiler to interpret statements correctly. For example in the CPU the instruction to add two integer values together is different from the instruction to add two floating-point values together. Hence the compiler must know the type of the variables so it can generate the correct add instruction.
It allows the compiler to decide how much storage space to allocate for storage of the value associated with the identifier and to assign an address for each variable which can be used in code generation.
    Difference of Defining & Declaring a variable
    Variable Definition specify the name and the type of the variable and also set aside memory space for the variable. A variable Declaration by contrast, specifies the variable’s name and data type but doesn't set aside any memory for the variable.
    In most cases the word “Declaration” is used for both meaning. 

    Posted by IRFAN 0 comments


    A variable is a space in a computer’s memory set aside for a certain kind of data and given a name for easy reference.or A variable is the name used for the quantities which are manipulated by a computer program. Variables are used so that the same memory space in memory can hold different values at different times.
    In order to distinguish between different variables, they must be given identifiers, names which distinguish them from all other variables. This is similar to elementary algebra, when one is taught to write ``Let a stand for the acceleration of the body ...''. Here a is an identifier for the value of the acceleration.

    Rules for a valid identifer or a variable name
    The rules of C and C plus plus  for valid identifiers state that: 
    An identifier must:
    start with a letter
    consist only of letters, the digits 0-9, or the underscore symbol _
    not be a reserved word 

    For the purposes of C/C++ identifiers, the underscore symbol( _ ) is considered to be a letter. Its use as the first character in an identifier is not recommended though, because many library functions in C++ use such identifiers. Similarly, the use of two consecutive underscore symbols, __, is forbidden. 
    The following are valid identifiers 
    length, days_in_year, DataSet1, Profit95 
    Int, _Pressure, first_one, first_1  
    The following are invalid:  
    days-in-year, 1data, int, first.val 
    Identifiers should be chosen to reflect the significance of the variable in the program being written. Although it may be easier to type a program consisting of single character identifiers but modifying or correcting the program becomes more and more difficult.
    The minor typing effort of using meaningful identifiers can make the program very user-friendly.
     At this stage it is worth noting that C++ is case-sensitive. That is lower-case letters are treated as distinct from upper-case letters. Thus the word main in a program is quite different from the word Main or the word MAIN. 

    Reserved words

    The syntax rules (or grammar) of C++ define certain symbols to have a unique meaning within a C++ program. These symbols, are called Reserved Words and must not be used for any other purposes.The reserved word already used in first C program was void. All reserved words are in lower-case letters. The list below shows the reserved words of C/C++. 
    and and_eq asm auto bitand  bitor bool break case catch char class const const_cast continue default delete do double dynamic_cast else enum explicit export extern false float for friend goto if inline int long mutable namespace new not not_eq operator or or_eq private protected public register reinterpret_cast return short signed sizeof static static_cast struct switch template this throw true try typedef typeid typename union unsigned using virtual void volatile wchar_t while xor xor_eq 
    Some of these reserved words may not be treated as reserved by older compilers. Other compilers may add their own reserved words. Typical are those used by Borland compilers for the PC, which add near, far, huge, cdecl, and pascal.

    Posted by IRFAN 0 comments

    #include< iostream.h >                              //header file:including instructions
    void main(void)                                                   //prototype of main function
    {                                                               //start of main function body
    cout<<"Hello Every body\n";                      //statements inside the main function
    cout<<"Welcome to the programming\n";                      //cout: displays output
    cout<<"This is my first C program\n";        // \n: used to move cursor to new line
    }                                                                      //End of main body

    Making an .exe File 

    After you have written the source file for your program, you need to turn it into an executable file. This is called “Making” the .exe file 


    The version of program you have typed in is understandable to humans. However it is not understandable to to the microprocessor in your computer.
    A program that has to be executed by the processor must be in the form of machine language file. Thus there must be two versions of C program which are as follows:
    The one which you type in which is called source file and other is the machine language version which is called executable or sometime called binary file.
    The compiler which is part of IDE translates this source code into another file, consisting of machine language. 
    There is another step on most compiled languages including Turbo C and Borland C : a process called Linking. Linking is necessary for several reasons. First, your program needs to be combined with other library routines. As we noted these are functions that performs tasks such as input/output. Library routines are stored in files with .lib extension 
    Secondly you may not want to compile all of your program at the same time. Larger C programs commonly consists of several separate files, some of which may already be compiled . The linker combines these files into a single executable file. 
    Like the compiler the linker is built into Turbo C’s IDE. The compiler generates an intermediate kind of file called an object file. The linker then links all the necessary object files together to produce a final executable program.

    Compiling and Linking in IDE

    In Turbo C compiling and linking can be performed together in one step. There are two ways to do this. 
    You can select Make EXE file from the compile menu or you can press the F9 key.

    Posted by IRFAN 0 comments

    The Integrated Development System:
    Turbo C features an integrated development environment or IDE. It is also referred as Programmer’s Platform. It is a screen display with windows and pull down menus. The program listing, its output, error messages and other information are displayed in separate windows.
    You use menu selections or key combinations to invoke all the operations necessary to develop your program, including editing, compiling, linking, and program execution. You can even debug your program within IDE.

    The Command-Line Development System

    You should be aware that there is another completely different way to develop C programs in Turbo C. This is a traditional command line system, in which editing, compiling, linking, debugging and executing are invoked from the DOS command line as separate activities, performed by separate programs.

    Unless you tell it, by default the install program puts all the sub-directories and files in a directory called TC. You can also change the name of directory and path to which directory will be created by install program. Do not change the name of sub-directories like BIN, INCLUDE, LIB and so on.

    Files used in C Program Development
    There are number of files which comes with Turbo C system. At this point, it is difficult to understand exactly what all these files do, but you should have rough idea before plugging to your first C program. These different files used are as follows.
    • Executable Files
    • Library and Run Time Files
    • Header Files
    • Programmer Generated Files
    Executable Files:
    These files are stored in the sub-directory BIN. The most important executable at least is TC.EXE. Executing this program loads the IDE on your screen. BIN directory also contains programs for the command line development process previously a bit discussed and utility programs for use in specialized situations. Here are some of them as follows.
    • TCC: Command-Line Compiler
    • TLINK: Command-Line Linker
    • MAKE: File Management Program
    • GREP: searches for strings in groups of files
    • TOUCH: updates file date and time
    • CPP: Preprocessor utility
    • TCINIST: customizes Turbo IDE.
    • TLIB: Library File Manager
    • UNZIP: unpacks ZIP (compressed) files
    • OBJXREF: object file cross-reference utility
    • THELP: popup utility to access help file
    Library and Run-Time Files:
    Various files are combined with your program during linking. These files contains routines for a wide variety of purposes. These are library files, run-time object files, and math library files. They are all stored in LIB directory.

    Library Files:
    Library files are groups of precompiled routines for performing specific tasks. For example, if programmer uses a function such as printf( ) which is described later to display text on screen, the code to create the display is contained in a library file. A library file has a unique characteristics i.e. only those part parts of it that are necessary will be linked to a program not the whole file.

    Math Libraries
    If you are using floating point arithmetic in your programs you will need another library file. For example, maths.lib, mathc.lib and so on.

    Run-Time Object Files:
    In addition to library files, each program must be linked with the run-time library object file. Such as c0s.obj, c0c.obj etc. These files contains the code to perform various functions after your program is running, such as interpreting command line arguments.

    Header Files:
    The sub directory called INCLUDE contains header files. These files are also called “include” files. These are text files like the one you generate with the word processor or Turbo C editor. Header files can be combined with your program before it is compiled.
    Header files serve several purposes. You can place statements in your program listing that are not program code but are instead messages to the compiler. These messages are called Compiler Directives, can tell the compiler such things as the definitions of words or phrases used in your program. Some useful compiler directives have been grouped together in header files, which can be included in the source code of your program before it goes to the compiler.
    Header files also contains the prototypes for the library functions. Prototypes provide the way to avoid program errors.later we will discuss in detail the header files and prototypes.

    Programmer Generated Files
    You can place your program anywhere on the Hard Disk. When IDE is loaded you can open it from the hard disk by giving path and enjoy your programming.

    Why does C uses so many files?

    Dividing the different aspects of the language into separate files gives the language more flexibility. By keeping the input / output routines in separate library files. For instance, it is easier to rewrite C to work on different computer. All that needs to be changed are the files containing I/O functions. The language itself remains the same.

    Posted by IRFAN Friday, April 2, 2010 0 comments

    Computer languages have undergone dramatic evolution since the first electronic computers were built to assist in telemetry calculations during World War II. Early on, programmers worked with the most primitive computer instructions: machine language. These instructions were represented by longstrings of ones and zeroes. Soon, assemblers were invented to map machine instructions to human-readable and -manageable mnemonics, such as ADD and MOV.
    In time, higher-level languages evolved, such as BASIC and COBOL. These languages let people work with something approximating words and sentences, such as Let I = 100. These instructions were translated back into machine language by interpreters and compilers. An interpreter translates a program as it reads it, turning the program instructions, or code, directly into actions. A compiler translates the code into an intermediary form. This step is called compiling, and produces an object file. The compiler then invokes a linker, which turns the object file into an executable program.Because interpreters read the code as it is written and execute the code on the spot, interpreters are easy for the programmer to work with. Compilers, however, introduce the extra steps of compiling and linking the code, which is inconvenient. Compilers produce a program that is very fast each time it is run. However, the time-consuming task of translating the source code into machine language has already been accomplished.
    Another advantage of many compiled languages like C++ is that you can distribute the executable program to people who don't have the compiler. With an interpretive language, you must have the language to run the program.
    For many years, the principle goal of computer programmers was to write short pieces of code that would execute quickly. The program needed to be small, because memory was expensive, and it needed to be fast, because processing power was also expensive. As computers have become smaller,cheaper, and faster, and as the cost of memory has fallen, these priorities have changed. Today the cost of a programmer's time far outweighs the cost of most of the computers in use by businesses.Well-written, easy-to-maintain code is at a premium. Easy- to-maintain means that as business requirements change, the program can be extended and enhanced without great expense.

    This is dedicated to Living memory of David Levine.

    Posted by IRFAN 0 comments