Reputation: 31
printf("variable = %d\n\n",*variable);
*variable=j;
printf("j= %d",j);
I have a bit in my code where If I print out the variable the pointer points to it prints the correct number but when I try to copy it to another variable (j in this case )it gives me a totally different one ( I assume it's a memory address since it changes when I edit the program ) but . What am I doing wrong ?
Upvotes: 1
Views: 54
Reputation: 53016
You are assigning j
to *variable
, not the other way, try like this
j = *variable;
I assume it's a memory address since it changes when I edit the program
It's not a memory address, it seems that j
is unintialized when you try to print it and in that case what you see printed is undeterminate indeed, it's called garbage and it can be anything, it can change when you change the program too. Also the behavior in that case is undefined so further using j
without initializing it could make the whole program hehave in an undefined way.
Upvotes: 4