passing arguments by address

Consider the following program. The function modifies the value of the variable "iNumber" and prints 6, but when I remove asterisk in the assignment (when I write k+=1 instead), it doesn't modifies the value of the variable "iNumber" in the caller and it prints 5. I would like to know specifically the way that this asterisk acts in the program. Moreover, are these two methods used in the programming?
1
2
3
4
5
6
7
8
9
10
11
12
13
#include <iostream>

void increase (int *k)
{
    *k+=1;
}

int main()
{
    int iNumber=5;
    increase (&iNumber);
    std :: cout << "The modified number is " << iNumber << "." << std :: endl;
}
Last edited on
The asterisk on line 5 is the dereference operator. http://www.cplusplus.com/doc/tutorial/pointers/
Topic archived. No new replies allowed.