Hello there! I’ve been studying C during this week and I came across a few (with a few I mean a lot) of questions regarding memory management.
So if I write the following code:
int main(void) {
string p;
print("p: ");
scanf("%s", &p);
}
When I create the variable p, the computer assigns a piece of memory to store whatever string we put into p and the operator &p seeks the memory address where p is located and stores the value we have given to p.
First question: is my interpretation correct?
Second question: if I declare p as a pointer, can I “get rid” of the assignment (&) operator?
e.g.:
int main(void) {
string *p;
print("p: ");
scanf("%s", p);
}
And lastly, how does scanf() differ from get_string(), get_int() etc? Essentially, I believe they do the same, which is getting input from the user, but when talking about memory, how different are their behaviors?