Every C++ program has a basic structure that helps the compiler understand what to do. Letβs break down the parts of a simple C++ program.
#include <iostream>
lets you use input-output functions.
using namespace std;
is used to access standard functions easily.
int main()
. It is the entry point of the program.
main()
that perform tasks, like printing output.
return 0;
indicates the program ended successfully.
#include <iostream> // Preprocessor directive using namespace std; // Namespace int main() { // Main function cout << "Welcome to C++!"; // Output statement return 0; // Return statement }
#include <iostream>
includes standard input-output stream library.using namespace std;
allows you to use standard functions like cout
without prefixing std::
.int main()
is the starting point of every program.cout
prints the message Welcome to C++! on the screen.return 0;
signals that the program ended without errors.The basic structure of a C++ program includes a preprocessor directive, namespace, main function, executable statements, and a return statement. This simple framework helps in building complex programs.
Help others discover Technorank Learning by sharing your honest experience.
Your support inspires us to keep building!