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 9220031
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T03:15:13+00:00 2026-06-18T03:15:13+00:00

Possible Duplicate: How come an array’s address is equal to its value in C?

  • 0

Possible Duplicate:
How come an array’s address is equal to its value in C?

In the situation:

int x = 5;
unsigned char myArray[sizeof (int)];

This line…

memcpy (&myArray , &x , sizeof (int));

… is producing identical results to:

memcpy (myArray , &x , sizeof (int));

I am very much a novice to C++, but I was under the impression that arrays are just a pointer to their data. I was shocked when &myArray was working identical to myArray. I would have thought it would be trying to copy to the ADDRESS of the pointer, which would be very bad!

  • 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-18T03:15:15+00:00Added an answer on June 18, 2026 at 3:15 am

    Two things about arrays:

    • Arrays “decay” to pointers of their element type. This is why the second version is working. See this :Is an array name a pointer?

    • There is such a thing as a “pointer to array”. They are rarely used, but look like this:


    int a[5];
    int (*b)[5] = &a; // pointer to an array of 5 ints
    

    The & operator when used on an array gives you a pointer to array type, which is why the following doesn’t work:

    int* b = &a; // error
    

    Since memcpy‘s parameter is a void*, which accepts any pointer type, both &myArray and myArray work. I’ll recommend going with myArray though as it’s more idiomatic.

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

Sidebar

Related Questions

Possible Duplicate: C: How come an array’s address is equal to its value? int
Possible Duplicate: C: How come an array’s address is equal to its value? Could
Possible Duplicate: C: How come an array’s address is equal to its value? C
Possible Duplicate: C: How come an array’s address is equal to its value? SA
Possible Duplicate: C: How come an array’s address is equal to its value? I
Possible Duplicate: Negative array indexes in C? How come this compiles, and runs as
Possible Duplicate: selecting items that come after a specific value i asked this allready
Possible Duplicate: C# Why can equal decimals produce unequal hash values? I've come across
Possible Duplicate: Sort array of objects sort an object array in php EDIT: This
Possible Duplicate: Where does the value of CXX in a makefile come from? I'm

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.