Advertisement

scanf/printf parameters

Started by November 14, 2001 09:52 AM
1 comment, last by Maydrock 23 years, 1 month ago
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.
novice programming mage
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
------------------------------------KaBeeM Web
<><
Advertisement
Ah!.....

*runs back to mage tower, reagents bouncing out of his pockets, to master the next concept in creating his own dimension*

novice programming mage
novice programming mage

This topic is closed to new replies.

Advertisement