printf and scanf

This is a discussion on printf and scanf within the C Programming forums, part of the General Programming Boards category; basic question. why in the printf statement we have the variable and in the scanf we have the address of ...

  1. #1
    Registered User
    Join Date
    May 2004
    Posts
    70

    printf and scanf

    basic question.

    why in the printf statement we have the variable and in the scanf we have the address of the variable.

    is there a reason behind this?

  2. #2
    & the hat of GPL slaying Thantos's Avatar
    Join Date
    Sep 2001
    Posts
    5,681
    printf only needs a copy of the values.
    scanf needs the address so it can make a change to the variables

  3. #3
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,851
    Because scanf() needs to write answers back into those variables, so it needs to know where to store the answers
    printf() doesn't know about the variables at all, it only knows about the values passed as parameters.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  4. #4
    Registered User
    Join Date
    May 2004
    Posts
    70
    ok, so printf is given the bare minimum.
    thanks, that make sense

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 2
    Last Post: 03-05-2009, 10:25 AM
  2. Data Structure Eror
    By prominababy in forum C Programming
    Replies: 3
    Last Post: 01-06-2009, 09:35 AM
  3. Newb Help: Full Arrays and Functions
    By LycanGalen in forum C Programming
    Replies: 5
    Last Post: 01-31-2008, 08:35 PM
  4. Please help debug
    By Wexy in forum C Programming
    Replies: 2
    Last Post: 11-11-2002, 12:40 AM
  5. help with switch statements
    By Wexy in forum C Programming
    Replies: 3
    Last Post: 11-06-2002, 05:44 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21