3i Infotech Placement: Sample Questions 503 - 503 of 1245

Glide to success with Doorsteptutor material for competitive exams : get questions, notes, tests, video lectures and more- for all subjects of your exam.

Question 503

Describe in Detail Essay▾

How would you use the functions memcpy () , memset () , memmove () ?

Edit

Explanation

  • memcpy ()
    • Copies bytes of data between memory blocks- called buffers.
    • doesn՚t care about the type of data being copied.
    • Simply makes an exact byte-for byte copy.
    • The function declaration is
      • void ⚹ memcpy (void ⚹ dest, void ⚹ src, size_t count) ;
      • Arguments dest and src point to the destination and source memory blocks.
      • Count specifies the number of bytes to be copied.
  • Memmove ()
    • Copies a specified number of bytes from one memory block to another.
    • More flexible, as it can handle overlapping memory blocks- can do everything memcpy () can with flexibility of dealing with overlapping blocks.
    • The function declaration is
    • Void ⚹ memmove (void ⚹ dest, void ⚹ src, size_t count) ;
    • Dest and src point to destination and source memory blocks
    • Count specifies the number of bytes to copied.
    • The return value is in dest.
  • Memset ()
    • To set all the bytes in a block of memory to a particular value, use memset ()
    • memset () initializes a block of memory to a specified value.
    • Void ⚹ memset (void ⚹ dest, int c, size_t count) ;
    • Dest points to the block of memory.
    • C is of type int but treated as a type char-, only the low-order byte is used, and we specify values of c only in the range 0 through 255.
  • Function useful only with type char- useful for blocks of data types other than char only when they are to be initialized to 0.