Basic HTML Version

|  | Table of Contents |  | View Full Version

Page 132 - CoreGPT(Podar)_Flipbook_C8
P. 132

    Now if you run the program, the output screen will appear.           Hello World_

                      To get back to the editor, press the Enter key.
                                                                                                       Output
                            STRUCTURE OF A C++ PROGRAM

                      A program is a set of statements, where each statement has a specific meaning and purpose. To
                      understand the program better, let’s number each line of the code:

                      #include<iostream.h>
                      #include<conio.h>
                      void main()

                      {
                          clrscr();
                          cout<<"Hello World";
                          getch();

                      }
                        C++ Statement                                       Description

                        <iostream.h>        The # symbol indicates a preprocessor directive. It instructs the compiler
                                            to include the iostream.h header file before compilation. This header file
                                            provides predefined objects such as cout, which is used for displaying
                                            output. Without including iostream.h, the cout object cannot be used.
                        include<conio.h> This line includes the  conio.h  header  file.  The  conio.h  file  provides
                                            predefined functions such as getch(), which is used for handling console

                                            input.
                        void main()         This line defines the main() function, which serves as the entry point of the
                                            program. Every C++ program must have a main() function, as execution
                                            starts from this function.

                        {                   The opening curly brace { marks the beginning of the main() function’s body.
                        clrscr();           The clrscr(); function is used to clear the console screen before displaying
                                            output. This ensures that any previous output does not interfere with the
                                            current program output.

                        cout<<"Hello  This line contains the cout object, which is used to print messages on the
                        World";             output screen. The message to be displayed must be enclosed in double
                                            quotes. In this case, it prints "Hello World". At the end of the line, a
                                            semicolon (;) is used as a statement terminator. In C++, each statement
                                            must end with a semicolon.
                        getch();            The getch() function is used to pause the program execution until a key is

                                            pressed. This ensures that the output window remains open until the user
                                            interacts with the keyboard.
                        }                   The closing curly brace } marks the end of the main() function.

                    130     Premium Edition-VIII

| 127 128 129 130 131 132 133 134 135 136 137 |