RayNewb:
That said, I don't expect you to grok the concept of memory maps and memory management from what I wrote. These are big topics which are far more important than any one language or machine. The questions you've raised in this thread go to the basics of "What is a Computer?" and "How do Computers Work".
As much as I love to teach in this forum, and as much as I hope this forum is a place where people feel comfortable asking basic questions, if you want to understand these concepts, it's now time for you to enroll in a class. You need the basics of what a computer actually is, and then, if you really want to understand what you're asking in this thread, you will find the answer in a class on Assembly Language.
You're going to make everyone crazy if you keep nibbling at these concepts, one C statement at a time. These threads never really end, though mercifully you've chosen to close a few after 20 or 30 responses. If you keep flailing away, I and everyone else here will try our best, but you're wasting your own time by trying to deal with this kind of question in a forum.
You know it's funny you said this, because I just came to this conclusion myself over the the course of this thread. You mentioned that most students will simply accept that
this works like this and
that works like that and what not -- I've never been like that, as I'm sure you've been able to tell. I always have to keep digging until I'm confident that I've reach a point where there is nothing else to be found by continuing, and you're right -- that's not fair to all you guys around here -- that's not what you're here for, and I get that.
The thing is, I've got all these books on C, right, and they start teaching a concept on pointers or something and, naturally, it leaves some question open, and given my nature, I can't rightfully continue until I know the answer to that question. Of course, that question raises another, and then another, and another -- each deeper into the core of things until I reach a point where, as you said, I'm not even really learning C any more. I think it just took me digging this far down to realize that.
Anyways, I was about to say this in my post anyways, and reading what you said was a timely confirmation of that, so -- I will try to stick to questions that are either basic or, if not, then at least specific to something, instead of asking for general information on deeper issues such as these. I always feel like I have to keep learning until I know everything about a certain something, and right now that something is C, so, in that sense, telling me that what we are talking about is beyond C provided good closure for me in not worrying about the details of this stuff.
As far as the classes go, I think you're right on. I hadn't even considered that as an option. To me, learning something means cracking open a library of books on the subject and teaching myself -- even with college classes, I always take online courses where I end up doing the bulk of the work myself out of a text book.
Anyways, with all that aside, thanks for responding, Ray. I'm sorry to have had you thinking on this one that much. I guess I'm so novice with this stuff that part of me figures that this is just child's play for you guys, but I don't want any unreasonable amount of time spent answering my questions, so if a question is beyond any reasonable boundaries in the future, if it's not something that can reasonably be answered on these forums, then just tell me so -- I won't be offended.
In terms of pointers/arrays and scanf(), your post was definitely helpful to me -- in particular the paragraph that started with "the answer is that the address stored in userName is random..." I think your post (in combination with the other guys') gave me enough of an answer for me to rest in peace on this one. 🙂 Thanks, Ray.
Bob:
I like your analogies, and they aren't bad ones at all. The concept of arrays and pointers in general is one that I actually do understand, but the analogy certainly didn't hurt to help cement those concepts into place, and it was particularly helpful in applying those concepts to the issue at hand (with scanf), so thank you for that.
The paragraph beginning with "scanf() wants a character array to store stuff into" was very enlightening in how simple it was. That may have been the general answer I was looking for. Thanks for your posts, Bob.
etresoft:
Thanks for the explanations. The only question left that I would have is, given your explanation about how anything before the semicolon is an initialization, then what about if you put the assignment on a separate line, like:
char * pChar;
pChar = "Tron";
You mentioned, though, the "address of a string literal in memory" and that made me remember something I read, that string literals are taken and stored at their own address (or something like that), so when you assign a string literal to something you are actually assigning the address of a string literal to it, so that might answer my question. In either case, I'm not worried about it, I'm going to close this thread out, but thank you for all your responses in this thread -- they were very helpful.