01 General Structure
01 General Structure
C++ is a free-form language. That is, the C++ compiler does not
care, where on the line we begin typing. While this may be a license
for bad programming, we should try to use this fact to our
advantage in developing readable programs. Although, several
alternative styles are possible, we should select one style and use it
with total consistency.
A simple program:
#include<iostream>
using namespace std;
void main()
{
cout<<“Hello, how are you ?” ;
}
Here observe that the documentation section, definition
section and global declaration section are absent. Also the
subprogram section is also absent. But this program has a
main function which is must for every program.
DIRECTIVES
The two line that begin the first example are directives. The first is a
preprocessor directive and the second is a using directive. They are
not part of basic C++ language, but they are necessary.
Preprocessor Directives
The first line of the example is:
#include<iostream>
Might look like a program statement, but it is not a program
statement. It is not part of a function body and does not end with a
semicolon, as program statements must. Instead, it starts with a
number sign #, pronounced as hash. It is called a preprocessor
directive. Recall that program statements are instructions to the
computer to do something, like adding two numbers.
A preprocessor directive, on the other hand, is an instruction to the
compiler. A part of the compiler called the preprocessor deals with
these directives before it begins the real compilation process.
The preprocessor directive #include<iostream> tells the compiler to
insert another file into your source file. In effect, the
#include<iostream> is replaced by the contents of the file indicated.
Using an #include<iostream> directive to insert another file into
your source file.