Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

  1. Preprocessor directives - These are statements that begin with a # symbol and are used to include header files

    Code Block
    languagecpp
    #include <iostream>
  2. 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
    languagecpp
    using namespace std; // Allows you to use 'std' namespace elements without the 'std::' prefix
    
  3. The main function: This is the entry point of your C++ program. The execution of your program starts from the main function. It should have a return type of int (it can take command-line arguments)

    Code Block
    languagecpp
    int main() {
        // Your program logic goes here
    
        return 0; // Indicates successful execution
    }

Code Block
languagecpp
//  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
languagecpp
// Module 1 Demo1Demo
// Author: Sam Student
// Created on 1-9-2023.
// Demonstrate output and create new lines
// Code uses \n and endl

...