Page 12 - Modular_V1.1_Flipbook
P. 12
Running a Program
If your program is compiled successfully, then run the program by selecting the Run option
from the Run menu. When you run the previous program, the output is not visible. Because the
compiler is not able to hold the data required to keep the output window open. So, to view the
output, you can select the Window → Output option from the menu bar.
To open the output window automatically, you need to use the following lines of code:
a. #include<conio.h>: This line comes under the #include<iostream.h>.
b. getch(): This line comes at the end of the program before the ending brace ( } ).
For example:
#include<iostream.h>
#include<conio.h>
void main(){
cout<<”Hello World”;
getch();
}
Now if you run the program, the output screen will appear. To
get back to the editor, press the Enter key.
Output
STRUCTURE OF A C++ PROGRAM
A program is a set of statements. Every statement has a different meaning and use. Let’s give a
number to each line in the preceding code to understand it better.
#include<iostream.h> // Line 1
#include<conio.h> // Line 2
void main() // Line 3
{ // Line 4
cout<<”Hello World”; // Line 5
getch(); // Line 6
} // Line 7
In Line 1, the # symbol is used to include iostream.h header file. It tells the compiler to add the
iostream.h header file with source code before compiling the program. It is called pre-processor
directive. The iostream.h header file contains pre-defined objects like cout<<. We cannot use
the cout<< object without including the iostream.h header file.
Similarly, Line 2 is used to include the conio.h header file. The conio.h header file also provides
predefined functions like getch( ).
Line 3 is used to start the main( ) function. The main( ) function is the entry point for the
compiler. Every statement of the program should be written inside the main( ) function.
Line 4 contains an opening curly brace ( { ). The curly brace is used to start the body of the
main( ) function.
10 Touchpad MODULAR (Version 1.1)-X

