Tuesday, January 3, 2012

Programming...

Programming is a core activity in the process of performing tasks or solving problems with the aid of a computer. There are many different programming languages, and many ways to classify them.
In this field the 1st ever programming language I learnt was C++. Throughout it was completely a new experience.

Some C++ facts -
The C++ compiler ignores comments which start with
 double slashes " // " like this, up to the end of the line. 
         Comments can also be written starting with a slash followed by a star " /* "  and ending with a star followed by a slash " */ ". Comments written in this way can span more than one line. 
       Programs can be included with plenty of comments.

There are several general features of all C++ programs. It begins (after the comment lines) with the statement
 #include <iostream>

This statement is called an include directive. It tells the compiler and the linker that the program will need to be linked to a library of routines that handle input from the keyboard and output to the screen. The header file "iostream" contains basic information about this library. 
After the include directive is the line:
using namespace std;

This statement is called a using directive. The latest versions of the C++ standard divide names into subcollections of names called namespaces. This particular using directive says the program will be using names that have a meaning defined for them in the std namespace.
Some C++ compilers do not yet support namespaces. In this case you can use the older form of the include directive:
#include <iostream.h>
Much of the code you encounter in industry will probably be written using this older style for headers.


Because the program is short, it is easily packaged up into a single list of program statements and commands. After the include and using directives, the basic structure of the program is:
                                   int main() 
                                   {
                                        First statement;
                                        ...
                                        ...
                                        Last statement;
        
                                       return 0;
                                  }
                  
All C++ programs have this basic top-level structure. Notice that each statement in the body of the program ends with a semicolon. In a well-designed large program, many of these statements will include references or calls to sub-programs, listed after the main program or in a separate file. These sub-programs have roughly the same outline structure as the program here, but there is always exactly one such structure called main
When at the end of the main program, the line
return 0;
means--> return the value 0 to the computer's operating system to signal that the program has completed successfully. More generally, return statements signal that the particular sub-program has finished, and return a value, along with the flow of control, to the program level above.

When programming we uses variables. Program variables are not like variables in mathematics. They are more like symbolic names for pockets of computer memory which can be used to store different values at different times during the program execution. Variables should always be declared before being used in a program. Indeed, it is considered good style and practice to declare all the variables to be used in a program or sub-program at the beginning. Variables can be one of several different types in C++.

No comments:

Post a Comment