0x00 In C - C Board

C Board
  • Register
  • Remember Me?
  • Advanced Search
  • Home
  • Forum
  • General Programming Boards
  • C Programming
  • 0x00 in C
Thread: 0x00 in C
  • Thread Tools
    • Show Printable Version
    • Email this Page…
    • Subscribe to this Thread…
  • Search Thread
    • Advanced Search
  • Display
    • Linear Mode
    • Switch to Hybrid Mode
    • Switch to Threaded Mode
  1. 08-16-2009 #1 vandrea
    • View Profile
    • View Forum Posts
    vandrea is offline Registered User Join Date Aug 2009 Posts 26

    Lightbulb 0x00 in C

    Hi all, Just had q query wrt to the string "0x00" used in memset of character arrays in C. Could anyone reply on this!! Thanks, Vandrea
  2. 08-16-2009 #2 Sebastiani
    • View Profile
    • View Forum Posts
    Sebastiani is offline Guest Sebastiani's Avatar Join Date Aug 2001 Location Waterloo, Texas Posts 5,708
    I don't understand your question. You don't pass a string to memset. If you're talking about the integral constant 0x00, it's just the hex encoding of, well, 0.
  3. 08-16-2009 #3 vandrea
    • View Profile
    • View Forum Posts
    vandrea is offline Registered User Join Date Aug 2009 Posts 26

    Smile

    yep u were right..i meant of the integral constant! Consider the follg eg: Code: char abc_ca[3]; memset(abc_ca,0x00,size(abc_ca)); So after the above memset i would have following values in my string Code: abc[0]={'\0'} abc[1]={'\0'} abc[2]={'\0'} where {'\0'} identifies the end of string...Just wanted to know if my understanding is right!
  4. 08-16-2009 #4 Sebastiani
    • View Profile
    • View Forum Posts
    Sebastiani is offline Guest Sebastiani's Avatar Join Date Aug 2001 Location Waterloo, Texas Posts 5,708
    Yep. On a side note, though, just keep in mind that sizeof used in that way won't work on an array passed to a function or on a pointer to an array.
  5. 08-16-2009 #5 vandrea
    • View Profile
    • View Forum Posts
    vandrea is offline Registered User Join Date Aug 2009 Posts 26
    Thanks Sebastiani for the quick reply...but dint get as to why cant we use sizeof in memset ?
    Last edited by vandrea; 08-16-2009 at 04:22 AM. Reason: error
  6. 08-16-2009 #6 Sebastiani
    • View Profile
    • View Forum Posts
    Sebastiani is offline Guest Sebastiani's Avatar Join Date Aug 2001 Location Waterloo, Texas Posts 5,708
    Well, for example: Code: int main( void ) { char buf[ 1024 ], * ptr = buf; printf("sizeof( buf ): %d\n", sizeof( buf ) ); printf("sizeof( ptr ): %d\n", sizeof( ptr ) ); return 0; } And when you pass an array to a function, it resolves to a pointer, so the effect is the same as in the second print statement.
  7. 08-16-2009 #7 vandrea
    • View Profile
    • View Forum Posts
    vandrea is offline Registered User Join Date Aug 2009 Posts 26
    Well, for example: Code: Code: int main( void ) { char buf[ 1024 ], * ptr = buf; printf("sizeof( buf ): %d\n", sizeof( buf ) ); printf("sizeof( ptr ): %d\n", sizeof( ptr ) ); return 0; } And when you pass an array to a function, it resolves to a pointer, so the effect is the same as in the second print statement. I understood ur example but still wondering as to y cant we use sizeof in the above memset since Code: sizeof(abc_ca) wuld return 3 I guess..
  8. 08-16-2009 #8 Sebastiani
    • View Profile
    • View Forum Posts
    Sebastiani is offline Guest Sebastiani's Avatar Join Date Aug 2001 Location Waterloo, Texas Posts 5,708
    >> I understood ur example but still wondering as to y cant we use sizeof in the above memset since The point is simply that you can use it on 'buf' but not 'ptr'. And inside a function, you'd have the same problem: Code: void test( char buf[ 1024 ] ) { printf("sizeof( buf ): %d\n", sizeof( buf ) ); }
  9. 08-16-2009 #9 vandrea
    • View Profile
    • View Forum Posts
    vandrea is offline Registered User Join Date Aug 2009 Posts 26
    Thanks Sebastiani...Now I get it!
Quick Navigation C Programming Top
  • Site Areas
  • Settings
  • Private Messages
  • Subscriptions
  • Who's Online
  • Search Forums
  • Forums Home
  • Forums
  • General Programming Boards
    1. C++ Programming
    2. C Programming
    3. C# Programming
    4. Game Programming
    5. Networking/Device Communication
    6. FAQ Board
    7. Programming Book and Product Reviews
  • Platform Specific Boards
    1. Windows Programming
    2. Linux Programming
  • Cprogramming.com and AIHorizon.com's Artificial Intelligence Boards
    1. General AI Programming
  • Community Boards
    1. Article Discussions
    2. Tech Board
    3. General Discussions
    4. A Brief History of Cprogramming.com
    5. Contests Board
    6. Projects and Job Recruitment
« Previous Thread | Next Thread » Popular pages
  • Exactly how to get started with C++ (or C) today
  • C Tutorial
  • C++ Tutorial
  • 5 ways you can learn to program faster
  • The 5 Most Common Problems New Programmers Face
  • How to set up a compiler
  • 8 Common programming Mistakes
  • What is C++11?
  • Creating a game, from start to finish
Recent additions
  • How to create a shared library on Linux with GCC - December 30, 2011
  • Enum classes and nullptr in C++11 - November 27, 2011
  • Learn about The Hash Table - November 20, 2011
  • Rvalue References and Move Semantics in C++11 - November 13, 2011
  • C and C++ for Java Programmers - November 5, 2011
  • A Gentle Introduction to C++ IO Streams - October 10, 2011

Similar Threads

  1. Encryption/Decryption Help
    By coolage in forum C++ Programming Replies: 9 Last Post: 04-25-2008, 01:53 AM
  2. To generate bar code from a number
    By darkducke in forum C Programming Replies: 18 Last Post: 01-16-2008, 06:33 AM
  3. brace-enclosed error
    By jdc18 in forum C++ Programming Replies: 53 Last Post: 05-03-2007, 05:49 PM
  4. Compile time switch
    By Roaring_Tiger in forum C Programming Replies: 13 Last Post: 09-12-2004, 01:16 PM
  5. Encryption Algorithms
    By face_master in forum C++ Programming Replies: 15 Last Post: 06-18-2003, 01:28 PM

Tags for this Thread

[code]

View Tag Cloud

-- Normal Style -- Mobile Style -- Default Mobile Style All times are GMT -6. The time now is 11:11 PM. Powered by vBulletin® Version 4.2.5 Copyright © 2024 vBulletin Solutions Inc. All rights reserved. Search Engine Optimisation provided by DragonByte SEO v2.0.40 (Pro) - vBulletin Mods & Addons Copyright © 2024 DragonByte Technologies Ltd.

Từ khóa » C++ 0x00