I have two code with different output.Need a good explanation, how its working in memory.
#include "stdafx.h"
int *fun(int *j)
{
*j++;
return j;
}
int _tmain(int argc, _TCHAR* argv[])
{
int i = 10;
int *j,*k;
j = &i;
k = fun(j);
printf("Now the value = %d",i);
printf("Now the value = %d",*j);
printf("Now the value = %d",*k);
return 0;
}
Here output is : 10,10 and -(some value).
If I change the bracket like following then:
#include "stdafx.h"
int *fun(int *j)
{
(*j)++;
return j;
}
int _tmain(int argc, _TCHAR* argv[])
{
int i = 10;
int *j,*k;
j = &i;
k = fun(j);
printf("Now the value = %d",i);
printf("Now the value = %d",*j);
printf("Now the value = %d",*k);
return 0;
}
Here output is : 11,11,11
This is I'm doing in Visual studio.Please give a good explanation.Thanks.