We get to that point, c++, this chapter mainly introduce parts of c++, and understand them with many code example.

hello world

first program "hello world", using std cin and out.

1
2
3
4
5
6
7
8
#include <iostream>
int main()
{
using std::cout;
using std::endl;// only use the 2 elements in standard namespace
cout << "Hello Buggy World \n";
return 0;
}

brief introduction of fuction

first touch of function in c++

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
#include <iostream>
using namespace std;
int ConsoleOutputTemp();
int main()
{
ConsoleOutputTemp();
return 0;
}
int ConsoleOutputTemp()
{
cout << "this is a simple string literal" << endl;
cout << "number 5 " << 5 << endl;
cout << "math problem 10/5 " << 10 / 5 << endl;
return 0;
}
## first glance at 'return value' return values using function
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
#include <iostream>
#include <string>
using namespace std;
int FuncInputDemoOne();
int main()
{
return FuncInputDemoOne();
}
int FuncInputDemoOne()
{
int inputNumber;
string inputName;
cout << "enter an integer " << endl;
cin >>inputNumber;
cout << "enter your name " << endl;
cin >> inputName;
cout << inputNumber << " " << inputName << endl;
return 0;
}
## '++i' vs 'i++' - ++i will increment the value of i, and then return the incremented value.

1
2
3
i = 1;
j = ++i;
(i is 2, j is 2)
  • i++ will increment the value of i, but return the original value that i held before being incremented.

    1
    2
    3
    i = 1;
    j = i++;
    (i is 2, j is 1)