0

Reading the value of a pointer from a function

double function (int x,int* pointer){ int address; /*this is the variable I want my pointer value to be saved in*/ pointer=&address; if(x==0) *pointer=1; else *pointer=0; return x; /*function does not return a pointer, but something else*/ } int main(){ int address; function(0,&address); printf("%d",address); } This code is a part of a larger code, but I'm only having problem with this part, so forgive me if it doesn't make much sense. How do I read the value of a pointer from a function and print it?

15th Dec 2019, 7:16 PM
mel1705
mel1705 - avatar
3 odpowiedzi
+ 2
mel1705 What is this code from? I hope it's not from something being built by professional developers. I'd be worried to see the rest of the code base.
15th Dec 2019, 9:39 PM
David Carroll
David Carroll - avatar
+ 2
Ah... I thought you were fixing someone else's code.
16th Dec 2019, 5:21 AM
David Carroll
David Carroll - avatar
+ 1
David Carroll no, this is part of my assignment, I am a beginner. And this is just a snippet I made to present a problem, not a real part of the code.
15th Dec 2019, 9:42 PM
mel1705
mel1705 - avatar