Basic Structure of C++

Basic Structure:
#include<header file> // Preprocessor Directive
void main()    //Program execution starting point
 {
     statement;
 } 

Example:
#include<iostream.h>
#include<conio.h>
void main()
{
      cout<<"hello";
}
 

Preprocessor Directive

Before a C++ program is compiled in a compiler, source code is processed by preprocessor. Commands used in preprocessor are called preprocessor directives and they begin with “#” symbol.
Ex: #include, #define etc.

Header File

A header file is a file with extension ".h" and contains some declarations of library functions. We use these header files in program by using preprocessor "#include".
Ex: #include<iostream.h>, #include<conio.h> etc.

main()

The main() function is the point from where all c++ programs start their execution.

Input Output (I/O) operations In C++ 

Input & Output operations are supported by the istream (input stream) and ostream (output stream) classes.
The predefined stream objects for input, output are :
(i) The cout Object:- The cout is a predefined object of ostream class that represents the standered output stream. cout stands for console output. cout sends all output to the standard output device i.e. monitor by using output operator (<<).
Syntax:- cout<< data; (Where data may be a variable or constant or string etc.)
Ex: cout<< avg;
       cout<<"Hello world";

(ii) The cin Object :- The cin object is an istream class object. cin stands for console input. cin object used to get input from the keyboard by using input operator(>>). When a program reaches the line with cin, the user at the keyboard can enter values directly into variables.
Syntax: cin>> variablename;
Ex: cin>> ch; ( here ch can be any variable)
 
Note: To use both cin and cout in a program a header file 'iostream.h' (input output stream) need to be include.

 

 

0 Comments:

Post a Comment

If you have any queries or suggestions, please let me know!