It's not so much a language as it is a particular way of describing a set of problems. At the very basic level, your processor understands a simple set of instructions: Add, subtract, multiply, divide read from memory, write to memory, and basic truth equations (and, or, not). You use a programming language to write a more human-readable program that can be turned into instructions for a machine.
The most basic component of a program is an expression or a statement- a single instruction for the computer to execute. Beyond that, you have blocks- groups of expressions. From there, you get control flow- only do something if a certain condition is true, or keep doing it until something changes. We can divide our code into functions (similar to mathematical functions) that take inputs and return outputs, to allow us to re-use code.
To start a program, you need a main function This is a function that takes arguments from the command line (if you aren't using the command line, the arguments are empty) and starts everything up. In C++, you declare the main function like this:
int main(int argv, char** argc)
int means that the function returns an integer number when it's done. Typically, it will return 0 if everything went ok. It will return a non-zero number: that's the error code you get when a program crashes. "main" is the name of the function.
Then, you get to the function arguments. This function has two: int argv and char** argc. argv is just a number telling you how many arguments there are. argc is rather complicated to explain exactly what it means, but suffice to say, it is a list of arguments ("char" means character- each word is made up of a list of characters, and then you have a list of those lists of characters).
Inside the body, you can do other things:
----------
//by the way, this is a comment
//I'll use them to tell you what's going on
//This statement right here is a special instruction
//it allows us to link with other people's code.
//in this case, I'm using the Input/Output library that
//comes with C++
#include
//and now here's our function
//the curly brace, {, says to start a block
int main(int argc, char** argv) {
//This, by the way is a comment- it starts with
//two slashes
//and here we have basic math.
//we add 1 and 2 and store it in a
//variable called 3
//statements end in a semicolon
int three = 1 + 2;
//and now here we have a conditional
//we have to use two equals signs
// because one means assignment
//all blocks start with braces
if(three == 3) {
//This writes to the console,
std::cout << "Yay! We Know Math.";
} else {
//this only gets executed
//if the condition was wrong
std::cout << "Wow we suck";
}
}
Of course ,there's so much more you can do with programs, but this is just sort of a quick, simple program for you to see how it works.