memset

This is a discussion on memset within the C Programming forums, part of the General Programming Boards category; Hello.. Is this memset(buf, 0, sizeof(buf)); the same as: memset(buf, '

Thread: memset

', sizeof(buf)); ? If no, whats the difference?...

  1. #1
    l2u
    l2u is offline
    Registered User
    Join Date
    May 2006
    Posts
    630

    memset

    Hello..


    Is this
    memset(buf, 0, sizeof(buf));

    the same as:
    memset(buf, '\0', sizeof(buf));

    ?

    If no, whats the difference?

  2. #2
    Gawking at stupidity
    Join Date
    Jul 2004
    Location
    Oregon, USA
    Posts
    3,171
    They're the same.
    If you understand what you're doing, you're not learning anything.

  3. #3
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,762
    Yes, they're the same.
    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
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,048
    And for good measure, Yes, it's really true, they're exactly the same thing!

    See the FAQ: http://faq.cprogramming.com/cgi-bin/...&id=1043284376
    dwk

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell


    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ: cpwiki.sf.net

    My website: http://dwks.theprogrammingsite.com/
    Projects: codeform, xuni, atlantis, nort, etc.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. info on memset and recv
    By lolguy in forum Networking/Device Communication
    Replies: 15
    Last Post: 11-12-2009, 05:48 AM
  2. Question about memset
    By Mortissus in forum C Programming
    Replies: 3
    Last Post: 03-24-2009, 09:16 AM
  3. Simple Question on Correct Usage of memset
    By deadpoet in forum C++ Programming
    Replies: 2
    Last Post: 03-16-2004, 08:58 AM
  4. memset has conflicting declaration
    By mangoMan in forum C++ Programming
    Replies: 2
    Last Post: 03-02-2004, 10:08 AM
  5. memset() or ZeroMemory()
    By jdinger in forum C++ Programming
    Replies: 2
    Last Post: 05-10-2002, 10:38 AM

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