Thread: Simple String question

  1. #1
    Registered User
    Join Date
    Jan 2013
    Location
    Kolkata
    Posts
    20

    Simple String question

    Why do we not pass the address of the string during printf or scanf functions like we do for Integer or float variable types?

    Thanks in advance.

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    But you DO pass an address.

    You just don't use the & address-of operator.

    Code:
    char message[] = "hello";
    printf("%s",message);
    // is the same as
    printf("%s",&message[0]);
    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.

  3. #3
    Registered User
    Join Date
    Jan 2013
    Location
    Kolkata
    Posts
    20
    Oh my. I missed that completely. Thanks a lot.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Simple string question
    By gareth00 in forum C Programming
    Replies: 12
    Last Post: 10-27-2008, 11:19 AM
  2. string simple question
    By -EquinoX- in forum C Programming
    Replies: 1
    Last Post: 04-12-2008, 01:28 PM
  3. simple question on std::string
    By MegaManZZ in forum C++ Programming
    Replies: 8
    Last Post: 01-25-2008, 12:18 PM
  4. Simple string question
    By RobJ in forum C Programming
    Replies: 6
    Last Post: 04-12-2006, 08:19 AM
  5. simple string question
    By c_cool in forum C Programming
    Replies: 4
    Last Post: 07-30-2004, 12:27 PM