General Structure of a C++ Program
- General Syntax:-
#include <iostream>
using namespace std;
int main() {
// Statements
return 0;
}
- Example of a Basic C++ Program
#include <iostream>
using namespace std;
int main() {
cout << “Welcome to C++ Programming!” << endl;
return 0; }
Output:-
Welcome to C++ Programming!
- Explanation of the Example
- The #include <iostream> directive tells the compiler to include the standard input-output stream library which is needed for using cout and cin.
- The using namespace std; statement allows direct access to all entities in the standard namespace without prefixing them with std::.
- The main() function is the entry point of a C++ program. Execution starts from this function.
- The cout statement is used to display output to the screen. The insertion operator (<<) sends the data to the output stream.
- The return 0; statement indicates that the program has executed successfully.
Difference between C and C++
