Hi, well, I've decided to start learning code, and I chose C, but I was reading the tutorial, and this one part really confused me. I just don't understand the purpose of the line, because the program runs the same with or without it, and the concept is confusing to me.
This is what the tutorial said
"This is where things start to get interesting: the scanf function works by taking a string and some variables modified with &. The string tells scanf what variables to look for: notice that we have a string containing only "%d" -- this tells the scanf function to read in an integer. The second argument of scanf is the variable, sort of. We'll learn more about what is going on later, but the gist of it is that scanf needs to know where the variable is stored in order to change its value. Using & in front of a variable allows you to get its location and give that to scanf instead of the value of the variable. Think of it like giving someone directions to the soda aisle and letting them go get a coca-cola instead of fetching the coke for that person. The & gives the scanf function directions to the variable. "
That kinda went completely over my head.
This is the code associated with what they are talking about
Code:
#include <stdio.h>
int main()
{
int this_is_a_number;
printf( "Please enter a number: " );
scanf( "%d", &this_is_a_number );
printf( "You entered %d", this_is_a_number );
getchar();
return 0;
}
What is the purpose of the whole this_is_a_number thing? What is the &?
Because if I delete all of the instances where it says thisisanumber, it runs the same, which is understandable to me, because the code makes sense. It is simply printing what it scanned for. I just don't get the thisisanumber thing.
I appreciate your response, and I hope one day I can look back at this and facepalm myself as you are probably doing right now.
Thanks,