C++ tutorial part I 03-30-2012, 05:29 PM
#1
because there's many tutorial for C++, i wanna make my own tutorial
(nice try, dude...)
ok, since C++ is either known as good programming language (read as: great) and, for that, is (one of) hacker's (best) choice, so it is a good point to learn this programming language.
btw, critics, opinions, and additions comes for this tutorial are perfectly welcomed (since i'm not really a master of C++)...
let's begin...
first of all, for you if you wanna know about: what is programming is, you can just go straight forward to this:
http://adf.ly/6qlhG
actually i never read it though, i define my own programming definition
right, let's start our first C++ code (program), here it is:
this is the most common program in every start of any programming language, "hello, world!" program.
the first line is a line of comment. we can write anything after the "//" marks. that note the compiler to ignore it and what lies after it (i.e. the sentence). it's useful to mark or commenting in certain part of the code, for remind us for what purpose that line are intended to.
the second and third line are code for including the iostream library and using the std namespace to use the input and output stream from iostream (am i right in this part?). the hash "#" is the preprocessor directives and "include" that follows it is the code for include a library. except directives, all the statements in C++ is ended with semicolon ";".
the fourth line, is... a blank space... i bet you all already know... congratulations...haha... ok, seriously, it's just for sake of neat of the source code and doesn't have an effect for the compiler...
the fifth line is the main function. it's the main function of our program, and it's where our program runs. and that the first function being called by the program when it runs. by its syntax, we can see that main is returning an int which is an integer data type of C++. and our main, this time, doesn't takes arguments. we'll learn about arguments, return type, data type later... the "{" brace is the symbol of the beginning of a block of statements. and in this case, the beginning of our function's block of statements (functions always have to begin and ended with braces too)
this line prints a "hello, world!" plus a newline at the screen. cout is the print statement. and the operator << (shift left) will extract the following sentences or data (e.g. variables, etc) through cout. endl statement is the newline statement. newline can be done with one of the escape characters, i.e. '\n'. but as far as i know, endl is a better choice, because it flushes the output buffer and then make a newline on the screen (CMIIW)
the returned value of the program, it exits with the value of 0 (zero) indicates the program is successfully exited. (i don't really know what it does)
the closing brace "}" is the end of the function, in this case, main function.
so, that's the end of my first C++'s tutorial. it's quite simple though, but, for the newbies for programming world, you all now can see more details of how a program flows...
please CMIIW
(nice try, dude...)ok, since C++ is either known as good programming language (read as: great) and, for that, is (one of) hacker's (best) choice, so it is a good point to learn this programming language.
btw, critics, opinions, and additions comes for this tutorial are perfectly welcomed (since i'm not really a master of C++)...
let's begin...
first of all, for you if you wanna know about: what is programming is, you can just go straight forward to this:
http://adf.ly/6qlhG
actually i never read it though, i define my own programming definition

right, let's start our first C++ code (program), here it is:
Code:
//the universal starting program ever, "hello, world!"
#include <iostream>
using namespace std;
int main() {
cout << "hello, world!" << endl;
return 0;
}this is the most common program in every start of any programming language, "hello, world!" program.
Code:
//the universal starting program ever, "hello, world!"Code:
#include <iostream>
using namespace std;the fourth line, is... a blank space... i bet you all already know... congratulations...haha... ok, seriously, it's just for sake of neat of the source code and doesn't have an effect for the compiler...
the fifth line is the main function. it's the main function of our program, and it's where our program runs. and that the first function being called by the program when it runs. by its syntax, we can see that main is returning an int which is an integer data type of C++. and our main, this time, doesn't takes arguments. we'll learn about arguments, return type, data type later... the "{" brace is the symbol of the beginning of a block of statements. and in this case, the beginning of our function's block of statements (functions always have to begin and ended with braces too)
Code:
cout << "hello, world!" << endl;Code:
return 0;the closing brace "}" is the end of the function, in this case, main function.
so, that's the end of my first C++'s tutorial. it's quite simple though, but, for the newbies for programming world, you all now can see more details of how a program flows...
please CMIIW
![[+]](https://sinister.ly/images/modern/collapse_collapsed.png)