A C++ Program consists of three main parts, These are:
- Preprocessor Directives
- The main () Function
- C++ Statements
Preprocessor Directives:
The instructions that are given to the compiler before the beginning of the actual program are called preprocessor directives. These are also known as compiler directives.
These directives normally start with a number sign # and keyword "include" or "define ". Preprocessor directives are used to include header files in the program.
Header file :
Header file is a C++ source file that contains definition of library functions . Header files are added into program at the time of compilation of the program. A header file is added if the function /object defined in it is to be used in the program.
The preprocessor directive “include” is used to add a header file into the program. The name of file is written in angle bracket < > after “# include” directive. It can also be written in double quotes.
- C++ has a large number of header files in which library functions are defined. The header file must be included in the program before calling its functions in the program.
- A single header file may contain a large number of built in library functions.
- For example ,the header file iostream.h has definition of different built in input output objects and functions.
main function
- The “main ()” function indicates the beginning of a C++ program.
The “main()” must be included in every C++ program.
- When a C++ program is executed, the control goes directly to the main() function.
- The statements within this function are the main body of the C++ program.
•If main() function is not included, the program is not compiled and an error message is generated .
The syntax of main() function is :
main ()
{
program statement….
}
Basic Input/Output Statement
- Input Statement: Those statements which are used to get data and then assign it to variables are known as input statements,
- Output Statements : Those statements which are used to receive data from the computer memory and then send it to the output devices are called output statements.
The "cout"object-output stream
The "cout" is pronounced as ‘see out’. The ’cout’ stands for console output. The console represents the computer display screen. The ‘cout’ is a c++ predefined object, it is used as an output statement to display output on the computer screen and it is a part of "iostream" header file.
Stream :flow of data from one location to another is called stream.
- The ‘ cout ’ is standard output stream in c++.
- This stream sends the output to the computer screen.
ConversionConversion EmoticonEmoticon