Basic

Github keep tracking and what is for ?

26 Oct , 2014  

When working with github, we usually do “push” and “pull” followed by “origin master” or “origin branch-name”. We can just use “git pull” or “git push” and will followed by the current branch.

For global push config using current:

1
git config --global push.default current

Example, we currently at branch “dev”. To push update, we can do:

1
git push origin dev

If we tracking dev branch using :

1
git branch --set-upstream-to=origin/dev dev

Then all we need just

1
git push

Basic

How to reverse variable array using pointer to pointer in C++

24 Nov , 2012  

Pointer to pointer is an reference that contain another pointer memory address. Remember, the reason it’s called pointer because it’s just pointing to another place that have “value”. Pointer is different with pointer to pointer. This is the simple explanation:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
#include<iostream>
#include<str using namespace std;

int main() {
    int customer = 1;
    int *pointerCustomer;
    int *pointerToPointerCustomer;

    pointerCustomer = &customer; // 1
    pointerToPointerCustomer = &pointerCustomer; // 2

    cout << **pointerToPointerCustomer; // 3

    return 0;
}

More…

,

Basic

How to counting array size and total element in C++

24 Nov , 2012  

Array in C++ is just same as variables that organized into one place. Basically, each element in array just stored sequentially in memory. To get the length of array, it just simple by get the size of array and divided it by the data type size. Since the way array stored the value sequentially, then it’s safe to doing this way:

1
2
3
4
5
6
7
8
9
10
11
12
13
#include<iostream>
using namespace std;

int main() {
    int student[] = {1, 2, 3};

    // Showing size of student array
    cout << sizeof(student);
    cout << "n";
    // Showing the element by divided by the data type size
    cout << sizeof student / sizeof(int);
    return 0;
}

Thanks to +Jon Dubovsky that’s give another response that we should carefull of using this kind of approach. We change the “student” int array into int (not array), this code still works but showing wrong results. That’s mean silently fail.

We can passing into as function to make compiler see the declaration of variable. The problem is array is just the way of organizing variables into one reference. You can’t to pass it into method and doing size calculation on it.

In this is example, i use Template :

1
2
3
4
5
6
7
8
9
10
11
12
#include<iostream>
using namespace std;

template<typename T, int size>
int countingArray(T(&)[size]){return size;}

int main() {
  int students[] = {1, 2, 3};
  cout << countingArray(students) << endl;

  return 0;
}

,