g++

Now I want to learn C++ on Linux… But it’s OK because this is my own space. I am just going over some basics on C++ coding.

#include <iostream>

using namespace std;

double square(double x)
{
    return x*x;
}

void print_square(double x)
{
    cout << "the square of " << x << " is " << square(x) << "\n";
}

int main()
{
    print_square(5);
}

I saved as helloworld.cpp. Now to compile it, I run…

g++ helloworld.cpp -o helloworld

It generates a binary file helloworld. When I execute it, it shows something like this…

the square of 5 is 25

Very simple, but I love something like this. When I start to learn a new language, I don’t use IDE. It makes me learn the language and how it works better.

Leave a Reply

Your email address will not be published.