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

  • SEARCH
  • Home
  • 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 9228649
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T05:22:34+00:00 2026-06-18T05:22:34+00:00

Say i have: unsigned char *varA, *varB, *varC; varA=malloc(64); varB=malloc(32); varC=malloc(32); How can i

  • 0

Say i have:

unsigned char *varA, *varB, *varC;
varA=malloc(64);
varB=malloc(32);
varC=malloc(32);

How can i put the first 32 byte of varA into varB and the last 32 byte of varA into varC?

  • 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-06-18T05:22:36+00:00Added an answer on June 18, 2026 at 5:22 am
    memcpy(varB, varA, 32);
    memcpy(varC, varA + 32, 32);
    

    It’s this simple because the underlying data type is unsigned char, which is the same size as a byte. If varA, varB, and varC were integers, you would need to multiply the size parameter to memcpy (i.e. 32) by sizeof(int) to compute the right number of bytes to copy. If I were being pedantic, i could have multiplied 32 by sizeof(unsigned char) in the example above, but it is not necessary because sizeof(unsigned char) == 1.

    Note that I don’t need to multiply the 32 in varA + 32 by anything because the compiler does that for me when adding constant offsets to pointers.

    One more thing: if you want to be fast, it might be sufficient to just work on each half of varA separately, rather than allocate two new buffers and copy into them.

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

Sidebar

Related Questions

Say you have methods int Read(...) { unsigned char Byte = 0; if(!ReadFile(.., &byte,
I have vector<unsigned char> filed with binary data. I need to take, lets say,
Say I have a two functions like the ones below: unsigned char PlusTwo(unsigned char
Say we have an 8-bit unsigned integer n ( UINT8_MAX=255 ); what is the
Let's say that I have a code like this: NSAutoreleasePool* pool=[[NSAutoreleasePool alloc]init]; for(unsigned int
Say I have a Telerik MVC Grid, AJAX bound and I want to put
I have a header file, wich contain a unsigned char array that is in
Say I have a float that I want to interpret as an unsigned int
Say I have the following table: create table ratings ( user_id int unsigned not
Let's say I have this program: class Foo { public: unsigned int bar ()

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.