Archived

This topic is now archived and is closed to further replies.

scanf/printf parameters

This topic is 5874 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

First off, I would like to say hello to everyone. This is my first post and have been looking over the site for a few weeks. Glad I found it. I have been taking a class in C this semester and still have a lingering question that I haven''t been able to answer yet and that is; why do you have to use an address operator with scanf parameters and not with printf parameters? It seems basically the parameters for the two functions are the complements of each other. The response I got from my professor was to my understanding that one person coded scanf and another person coded printf way back. It seems to me that it should be more to it than that. As of now though, it would be much simpler if both functions took ....hmmm... the same approach to parameter passing, especially once you start passing various levels of pointers. I have scanned the rest of the text trying to see if the subject is covered in more detail in a later section, but have not found anything. I don''t have a reference library to turn to, so if someone could direct me to a site/article that covers the subject in a little more detail, I would appreciate it, so that I could get this nagging question out of the back of my head and hopefully be able to start to understand do I put an &here, *variable here, **here.....etc. For any individual statement I can eventually get to the level of data that I need to, but to get to some level of data, I just don''t get why the scanf or printf parameter has to be coded differently. Thanks for your time.

Share this post


Link to post
Share on other sites
Isn''t it because scanf needs to be able to store data in the var. If it didn''t take a pointer, the only other way to get data out of the function would be for it to return the value. Even then it would probably return a void* so it could return strings. When you pass a regular variable to a function, the computer just makes a copy of it and sends it to the function. It doesn''t get access to the var you want to be changed. That''s why you have to pass a pointer.

I think that''s the answer to your question anyway.

Newbie to game programming?
visit

KaBooMgames
Great for Newbs, Masters welcome as well

Share this post


Link to post
Share on other sites