Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 746001
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T09:38:55+00:00 2026-05-14T09:38:55+00:00

According to http://en.cppreference.com/w/cpp/string/byte/memcpy C++’s memcpy takes three parameters: destination, source and size/bytes. It also

  • 0

According to http://en.cppreference.com/w/cpp/string/byte/memcpy C++’s memcpy takes three parameters: destination, source and size/bytes. It also returns a pointer.

void* memcpy( void* dest, const void* src, std::size_t count );

Why is that so? Aren’t the parameters enough to input and copy data?

Am I misunderstanding something? The examples don’t use the return value.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-14T09:38:55+00:00Added an answer on May 14, 2026 at 9:38 am

    If a function has nothing specific to return, it is often customary to return one of the input parameters (the one that is seen as the primary one). Doing this allows you to use “chained” function calls in expressions. For example, you can do

    char buffer[1024];
    strcat(strcpy(buffer, "Hello"), " World");
    

    specifically because strcpy returns the original dst value as its result. Basically, when designing such a function, you might want to choose the most appropriate parameter for “chaining” and return it as the result (again, if you have noting else to return, i.e. if otherwise your function would return void).

    Some people like it, some people don’t. It is a matter of personal preference. C standard library often supports this technique, memcpy being another example. A possible use case might be something along the lines of

    char *clone_buffer(const char *buffer, size_t size)
    {
       return memcpy(new char[size], buffer, size);
    }
    

    If memcpy did not return the destination buffer pointer, we’d probably have to implement the above as

    char *clone_buffer(const char *buffer, size_t size)
    {
       char *clone = new char[size];
       memcpy(clone, buffer, size);
       return clone;
    }
    

    which looks “longer”. There’s no reason for any difference in efficiency between these two implementations. And it is arguable which version is more readable. Still many people might appreciate the “free” opportunity to write such concise one-liners as the first version above.

    Quite often people find it confusing that memcpy returns the destination buffer pointer, because there is a popular belief that returning a pointer form a function should normally (or always) indicate that the function might allocate/reallocate memory. While this might indeed indicate the latter, there’s no such hard rule and there has never been, so the often expressed opinion that returning a pointer (like memcpy does) is somehow “wrong” or “bad practice” is totally unfounded.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 395k
  • Answers 396k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer ... group operation by new { operation.Debit, operation.Credit } into… May 15, 2026 at 2:49 am
  • Editorial Team
    Editorial Team added an answer as you found out, you cannot document 2 different signatures… May 15, 2026 at 2:49 am
  • Editorial Team
    Editorial Team added an answer When scrolling all the way to the bottom, this thould… May 15, 2026 at 2:49 am

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.