I am learning how to use pointers in C and I am having trouble with this little program. In main, I want to get the value in the parameter.
int testing(int *number) {
int num = 12;
number = #
return 0;
}
int main() {
int num;
testing(&num);
printf("The number is: %d", num);
return 0;
}
Essentially, I want to print the num pointer after it goes through the testing function. Therefore, I want num to be 12. Currently, when I print num, it is a random number. Any ideas? Thanks.
number = #
is changing the local parameter (copy of what is passed). This means nothing because number
is not used after that.
Instead of that, you should dereference the passed pointer to write the integer there: *number = num;
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments