I am a little bit newbie, and pointers still do troubles to me. I would like to change value of int, which I get from parameter (as a pointer) in function.
#include <stdio.h>
bool function(int* a){
a++;
printf("%d",*a); //getting some big number, maybe address. If i did not use a++; I get just normal a, unchanged.
return false;
}
The problem is that you're incrementing the pointer (not the value pointed with it) in the statement a++. If you want to increment the value of the parameter, you should dereference it first:
(*a)++; //instead of a++;
Printf is not printing exactly an address, is just printing the value of the integer (may be an integer, can be something else) stored next to your parameter a.
You need to dereference the pointer to get the actual value of the integer (not address) by using *a. Then you can increment that value. So your code should be (*a)++ instead of a++ (In your case you are just incrementing the address and trying to access the next location in memory).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With