filmov
tv
C++ Hello World Program| Visual Studio Code | Hello World Program | C++ tutorial #CodeOnTrend #C++
![preview_player](https://i.ytimg.com/vi/w-RMbt2FZnU/maxresdefault.jpg)
Показать описание
Let us go into the program and understand it line by line.
Line 1 – An include statement. We are including iostream header file to use the functionalities in it. There are many header files that come included with C++. You can include one header file using one include statement. To include multiple header files in your program, write an include statement for each one of them.
You can also create a header file of your own, in which you define some functionalities. And then you can include that header in your program.
Line 2 – Using namespace statement. Namespaces is kind of grouping of variables under a single name. In this statement we specified that we shall use the namespace named std. std has variables defined like cout which we used in the program in line 5. If you are not writing this using namespace statement, you have to write std::cout instead of cout. While going forward, you will see that writing this namespace statement is useful to ease out the code.
Line 3 – An empty line. You can write empty lines in your C++ program. This lets you have some space between your statements and function. Just to increase the readability of program. Empty lines or spaces are ignored by C++ compiler.
Line 4 – A function definition. We are defining a function named main that returns an integer and accepts no arguments. You will see main() in most of our C++ programs. This is because main() function is kind of an entry point to the execution of a C++ program. We also have a flower brace that starts the scope of this main() function.
Line 5 – cout can be used to write an object or value to standard output.
Line 6 – Ending flower bracket. This closes the scope of main function. Body of main() function, which includes all the statements inside it, should be enclosed between flower braces.
Conclusion
In this #C++ Tutorial, we learned how to write a basic hello world program in C++.