...
Preprocessor directives - These are statements that begin with a
#
symbol and are used to include header filesCode Block language cpp #include <iostream>
Namespace declaration - Namespaces are used to organize code and avoid naming conflicts between different libraries or modules. The
using namespace
directive allows you to use elements from a specified namespace without having to provide their fully-qualified names.Code Block language cpp using namespace std; // Allows you to use 'std' namespace elements without the 'std::' prefix
The
main
function: This is the entry point of your C++ program. The execution of your program starts from themain
function. It should have a return type ofint
(it can take command-line arguments)Code Block language cpp int main() { // Your program logic goes here return 0; // Indicates successful execution }
Code Block | ||
---|---|---|
| ||
// Demo1Module 1 Demo // Author: Sam Student // Created on 1-9-2023. // Demonstrate output and create new lines // Code uses \n and endl #include <iostream> // required library using namespace std; int main() { //output to the console cout << "This is my first line" << endl; cout << "This is my second line\n"; cout << "This is my third line" << endl; return 0; } // end of main |
...
Let's break down the code piece by piece:
Code Block | ||
---|---|---|
| ||
// Module 1 Demo1Demo // Author: Sam Student // Created on 1-9-2023. // Demonstrate output and create new lines // Code uses \n and endl |
...