ycliper

Популярное

Музыка Кино и Анимация Автомобили Животные Спорт Путешествия Игры Юмор

Интересные видео

2025 Сериалы Трейлеры Новости Как сделать Видеоуроки Diy своими руками

Топ запросов

смотреть а4 schoolboy runaway турецкий сериал смотреть мультфильмы эдисон
Скачать

Structure of C++ program | Preprocessor directives |Header files | A sample program Part 4

The preprocessor directive #include is used to link the header file iostream with the program

The using namespace statement makes available the identifier cout in the program

An opening brace { that marks the beginning of the instruction set

The return statement stops the execution of the main() function

Автор: High Tech classroom

Загружено: 2021-05-11

Просмотров: 11

Описание: Structure of C++ program

C++ program is a collection of one or more
functions. A function means a set of instructions
to perform a particular task referred to by a
name. Since there can be many functions in a
C++ program, they are usually identified by
unique names. The most essential function
needed for every C++ program is the main()
function
Preprocessor directives

A C++ program starts with pre-processor directives. Preprocessors are the compiler
directive statements which give instruction to the compiler to process the information
provided before actual compilation starts. Preprocessor directives are lines included in
the code that are not program statements. These lines always start with a # (hash)
symbol. The preprocessor directive#include is used to link the header files available
in the C++ library by which the facilities required in the program can be obtained. No
semicolon (;) is needed at the end of such lines. Separate #include statements
should be used for different header files. There are some other preprocessor directives
such as #define, #undef, etc.

Header files
Header files contain the information about functions, objects and predefined derived
data types and are available along with compiler. There are a number of such files to
support C++ programs and they are kept in the standard library. Whichever program
requires the support of any of these resources, the concerned header file is to be included.
For example, if we want to use the predefined objects cin and cout, we have to use
the following statement at the beginning of the program:
#include iostream
The header file iostream contains the information about the objects cin and cout.
Eventhough header files have the extension .h, it should not be specified for GCC.
But the extension is essential for some other compilers like Turbo C++ IDE

The main() function
Every C++ program consists of a function named main(). The execution starts at
main() and ends within main(). If we use any other function in the program, it is
called (or invoked) from main(). Usually a data type precedes the main() and in
GCC, it should be int.
The function header main() is followed by its body, which is a set of one or more
statements within a pair of braces { }. This structure is known as the definition of the
main() function. Each statement is delimited by a semicolon (;). The statements may
be executable and non-executable. The executable statements represent instructions to
be carried out by the computer. The non-executable statements are intended for compiler
or programmer. They are informative statements. The last statement in the body of
main() is return 0;. Even though we do not use this statement, it will not make
any error

A sample program
The program has seven lines as detailed below:
Line 1: The preprocessor directive #include is used to link the header file
iostream with the program.
Line 2: The using namespace statement makes available the identifier cout in
the program.
Line 3: The header of the essential function for a C++ program, i.e., int main().
Line 4: An opening brace { that marks the beginning of the instruction set (program).
Line 5: An output statement, which will be executed when we run the program, to
display the text "Hello, Welcome to C++" on the monitor. The header
file iostream is included in this program to use cout in this statement.
Line 6: The return statement stops the execution of the main() function. This
statement is optional as far as main() is concerned.
Line 7: A closing brace } that marks the end of the program

Не удается загрузить Youtube-плеер. Проверьте блокировку Youtube в вашей сети.
Повторяем попытку...
Structure of C++ program | Preprocessor directives |Header files | A sample program Part 4

Поделиться в:

Доступные форматы для скачивания:

Скачать видео

  • Информация по загрузке:

Скачать аудио

Похожие видео

© 2025 ycliper. Все права защищены.



  • Контакты
  • О нас
  • Политика конфиденциальности



Контакты для правообладателей: [email protected]