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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T17:04:32+00:00 2026-06-16T17:04:32+00:00

Possible Duplicate: How do I use arrays in C++? void fn(int a[3]) { a[5]=5;

  • 0

Possible Duplicate:
How do I use arrays in C++?

void fn(int a[3])
{
    a[5]=5;
}

int main()
{
    int A[10] = {0};
    cout<<A[5]<<endl;
    fn(A);
    cout<<A[5]<<endl;
}

For the first print statement I got A[5]=0 and for the second time A[5]=5. How does this code actually work ?

  • 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-16T17:04:33+00:00Added an answer on June 16, 2026 at 5:04 pm

    In C++ array from programmer’s view is almost equal to the pointer to its first element. In case of arrays passed by parameter, they are equal. If you imagine it this way, you pass the pointer to an array to function, then modify its sixth element (still the original!), and then display it.

    Your code is equal to:

    void fn2(int * a)
    {
        *(a + 5) = 5;
    }
    
    (...)
    
    fn(&(A[0]));
    

    Side note The difference in statically allocated and dynamically allocated arrays can be seen while playing around with local variables:

    int a[5];
    int * p;
    
    printf("%d %d\n", sizeof(a), sizeof(p));
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Possible Duplicate: How do I use arrays in C++? One dimensional array as a
Possible Duplicate: What is useful about a reference-to-array parameter? How do I use arrays
Possible Duplicate: How do I use arrays in C++? I have the following C
Possible Duplicate: How do I use arrays in C++? I am not sure if
Possible Duplicate: How do I use arrays in C++? In the following code snippet:
Possible Duplicate: Programmatically create static arrays at compile time in C++ I have lots
Possible Duplicate: Passing multidimensional arrays as function arguments in C I'm trying to use
Possible Duplicate: How do I use arrays in C++? To put it simply, is
Possible Duplicate: How do I use arrays in C++? Is 2d array a double
Possible Duplicate: Advantages of using arrays instead of std::vector? What are the main advantages/disadvantages

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.