C++ definition Tutorial

DeletedUser

Guest
Hi folks

Past few weeks I've been working on how to understand c++ language and finally I've found some success. C++ can be difficult at first but it requires patience and a bit of brains. Anyone can learn C++ but the only thing it requires is patience.

Now the simplest compiler in my opinion which is best for newbies is Code Block. The link for code block download is: http://sourceforge.net/projects/codeblocks/files/Binaries/10.05/Windows/codeblocks-10.05mingw-setup.exe/download

After you download it, you have yourself a compiler. It may not be the best but it's user friendly. Now create a project which uses Console Application template. Fill in the details and now open your Project.

Now you will see the simplest program:

1 #include <iostream>
2
3 using namespace std;
4
5 int main ()
6 {
7 cout << "Hello Grepolis" << endl;
8 return;
9
10 }

In this tutorial I will be breaking this program word by word, code by one until you understand all of it's definition and purposes.


This include <iostream> is called a preeprocesser directive. Pree Proccessor directive means that it's going to include a file iostream in this program which we're going to need later. The next line you'll see a blank line. Blank lines are not needed but are used to make your program neater and easier to read. Just like a book or a magizine. There's no limit to blank lines. You can have a million of them or 1 of them.

Under that blank is Using Namespace Std;. And believe it or not it does not stand for sexually transmitted diseases. Instead it stands for Standard library. And that's pretty much saying this: we're going to be using all the standard things in c++ plus, nothing fancy.


int main ()
6 {
7 cout << "Hello Grepolis" << endl;
8 return;
9
10 }

This entire thing is called a function. Computer programs are made up of functions. Functions are things you want the computer to do. For example if you're making a program to play sounds, you'll need a function which programs the computer to play sounds.. As you can see functions are just things you want the computer to do.

Every computer program start with a function code main. This is how your computer knows where to start. Main tells the computer the order of your program so it won't be confused and mess up the program with unnecessary errors. So that is why it's so crucial to name your function main.

In order to make a function you must write what type of data you're going to be working with. Functions typically do some sort of calculations. For example find the mass of an index or calculate the vosallity of something or w/e. It usually wants something back or an answer. So since we're going to be working with intergers we're going to need to put "Int" in our function.

Don't worry about these brackets. You just need em lads. Now you need squiggly brackets : {
}
Between the squiggly brackets are statements. All functions are made up of statements and all statements are basically instructions. Each instructions needs to end with a semi colon(;).

The first statement is cout. That's called an output stream object and is basically use to write words on the computer screen. That's how we're able to type hello world on the computer screen.

This << is called the conjuction stream operator which is used to take all this stuff in the right of it and prints it out on the screen. Cout << "Hello grepolis" << . Endl; means end line which pretty much means go to the next line.

That's all the meaning of this program. If you have any question pm me or make a comment. A simple program may look simple but it's complex. It's easy when you understand the code and know what they do. Rep me if you think this was helpful. I may make more tutorial depending on the comments.
 

DeletedUser

Guest
Sorry this is just a ruff and quick version of what it means. lol
 

DeletedUser

Guest
It's actually a good tutorial. No sarcasm or anything. Really good tut for beginners.
 

DeletedUser

Guest
Someone de-repped me and said "learn how a computer works first". Anyway my next tutorial will be about Variables and how you can make a calculator with one
 

DeletedUser

Guest
I hope this was helpful. I may be moving to conductors or variables depending on my time
 

Lugosi

Strategos
u kno it was u.

yeah wayne :3 ; stop accusing me when you don't know the truth or anything of the matter.

Thnx Raurio <3, I appreciate you putting wayne in his place ;3 xoxoxo

My rep comments are always way more colourful than that and they relate to the person skillfully unlike that one, that was very average

Still, I prefer firelord when he was like this; life was so much better . .
 

DeletedUser

Guest
Computer programs are made up of functions.
Not all computer programs are made up of functions.
In assembly language, it's just a bunch of processors instructions that are executed line after line.
In Java / C#, you need a base class that has a function that represents the start of the program, otherwise it won't compile.

Main tells the computer the order of your program so it won't be confused and mess up the program with unnecessary errors. So that is why it's so crucial to name your function main.
Actually main() tells the compiler that this is the start of the program and the code inside this function will be the main code in the assembly file then translated into the executable.

int main ()
6 {
7 cout << "Hello Grepolis" << endl;
8 return;
9
10 }

You've explained that functions return a type, and you've put int, but next on line 8 you write a blank return. Replace int with void, since you are actually not returning anything and remove the blank return. Sure it works like it's now but you are missing a key point. Usually main() has an int return type due to hystorical reasons - in UNIX(or other command lines) after you've executed the program (i think the IDE console should tell you this as well) most of the programs have execution return codes.

What is an execution return code? The actual value of main() as a number, that represents something. If the program executed successfully it would return 0. Otherwise it would return 1, 3, 525, -45 etc. each of them having a specific meaning.

So if you want to do it properly, you would do something like:

int main()
{
return 0;
}

If you want to make a definition of C++ tutorial based on console applications, i think you should understand and explain in your tutorial what a console application is in the first place.

How about starting with
int main(int argc, char** argv)
Which is the correct declaration of a proper console application main header (universal format, platform independent) that can receive parameters when called. Even if you don't use the command line parameters, you should still receive them in main() and ignore them if you want to.

This << is called the conjuction stream operator which is used to take all this stuff in the right of it and prints it out on the screen.
Correct, but it should be noted that the "<<" operator does this ONLY when used with the cout, cin objects, or other objects that have the << operator overloaded.
3 << 1 has a different meaning, and the meaning it has in THIS context is the base one in C++. It only prints when you use it on cout as a left side operator because the library you import has it declared to do it like this.

I'd suggest you start with a more in-depth learning about programs before you start Explaining people how things work. It's easier to understand a programming language AFTER you've already learned HOW the programs work.

Noble attempt tho but it requires more background information - the complex things you;ve mentioned should be explained.
 

DeletedUser

Guest
Okay thanks, I can see where I've gone wrong. I should probably learn more c++ before teaching others
 

DeletedUser

Guest
I love CodeBlocks :D You should check out TheNewBoston on youtube, he makes great tutorials.
 
Top