Let's start C++
- Writing your first C++ program: Hello world!
Writing your first C++ program is an exciting step in learning programming. The classic "Hello World!" program is a great starting point.
In simple terms, it involves telling the computer to display the words "Hello World!" on the screen. This simple program introduces you to the basic structure and syntax of C++. It may seem small, but it lays the foundation for more complex programs you'll write in the future.
FILE:TUT1.CPP
Printing Hello world! :
#include<iostream>
int main()
{
std::cout << "Hello World!" << std::endl;
return 0;
}
Output:
Hello world!
- Basic structure of a C++ Program:
#include<iostream> : This line contains the appropriate library called that provides
functionality for input and output operations.
int main() {...}: This is the main function that acts as the entry point of the program. All code
inside the curly braces {... } is wrapped in the main function.
std::cout << "Hello World!" << std::endl;: This line, "Hello World!" uses std::cout to print
its text to the console or screen.
The << operator is used to add text to the output. 'std::endl' is used
to insert a new line after printing.
return 0;: this line marks the end of the 'main' function and usually returns 0, which indicates
the completion of the program.