For some reason it prints 1 instead of 2 and i cant tell why.
#include <stdio.h>
#include <stdlib.h>
void f(int *p)
{
*p++;
}
int main()
{
int k=1;
f(&k);
printf("%d",k);
return 0;
}
Because you increment the pointer address and not it's value. Wrap it with parenthesis:
#include <stdio.h>
#include <stdlib.h>
void f(int *p)
{
(*p)++;
}
int main()
{
int k=1;
f(&k);
printf("%d",k);
return 0;
}