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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T02:25:45+00:00 2026-06-13T02:25:45+00:00

Possible Duplicate: Confusion over C++ pointer and reference topic Suppose I am passing int

  • 0

Possible Duplicate:
Confusion over C++ pointer and reference topic

Suppose I am passing

int arr[10];

as a parameter to a function.

Are all of these valid function prototypes? How do they differ in terms of arguments and why?

This is what I know so far (not sure if correct or not)

1. void foo(int &arr);      //a reference to an array, which preserve the size attribute?
2. void foo(int &arr[]);    //the same (is it)?
3. void foo(int (&arr)[]);  //I don't know
4. void foo(int &arr[10]);  //is it the same as 2?
5. void foo(int (&arr)[10]);//no idea

6. void foo(int *arr);      //a decayed pointer of the array, pointing to the first element of the array, losing the size attribute?

7. void foo(int *arr[]);    //the same (is it?)
8. void foo(int (*arr)[]);  //a pointer to an array, preserve the size
9. void foo(int *arr[10]);  //the same as 7 (is it?)
10. void foo(int (*arr)[10]);//is the same as 8 (is it?)

11. void foo(int arr[]);    //is the same as 6 (is it?)
12. void foo(int arr[10]);  // is the same as 6 (is it?)

(I know this will need a lengthy explanation, sorry, I’m totally confused…)

  • 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-13T02:25:47+00:00Added an answer on June 13, 2026 at 2:25 am

    The first important piece of information is that parameters whose type is a (bounded or unbounded) array of T are transformed to pointers to T. I.e. both int arr[] and int arr[10] are transformed to int * arr. Note that the transformation is only performed on top-level arrays, i.e. it doesn’t occur in int (*arr)[10], which is a pointer to an array of int.

    Furthermore, things to the right of the identifier bind more closely than things to the left, i.e. int *arr[10] is an array, whereas int (*arr)[10] is a pointer.

    Lastly, arrays of and pointers to references are invalid, as are pointers and references to unbounded arrays.

    1. void foo(int &arr);        // can't pass, reference to int
    2. void foo(int &arr[]);      // invalid, pointer to reference to int
    3. void foo(int (&arr)[]);    // invalid, reference to unbounded array of int
    4. void foo(int &arr[10]);    // invalid, pointer to reference to int
    5. void foo(int (&arr)[10]);  // can pass, reference to an array of int
    
    6. void foo(int *arr);        // can pass, pointer to int
    7. void foo(int *arr[]);      // can't pass, pointer to pointer to int
    8. void foo(int (*arr)[]);    // invalid, pointer to an unbounded array of int.
    9. void foo(int *arr[10]);    // can't pass, pointer to pointer to int
    10. void foo(int (*arr)[10]); // can't pass, pointer to array of int
    
    11. void foo(int arr[]);      // can pass, pointer to int
    12. void foo(int arr[10]);    // can pass, same as above
    

    Using arr as an argument to foo will cause it to decay to a pointer to its first element — the value passed to foo will be of type int *. Note that you can pass &arr to number 10, in which case a value of type int (*)[10] would be passed and no decay would occur.

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

Sidebar

Related Questions

Possible Duplicates: Why use pointers? Passing a modifiable parameter to c++ function Why would
Possible Duplicate: What are the differences between pointer variable and reference variable in C++?
Possible Duplicate: Difference between pointer variable and reference variable in C++ As I am
Possible duplicate Hello all. I have confusion in drop query that how actually it
Possible Duplicate: JavaScript BlockStatement confusion Why does {10 + '1'} + 10 equal 10?
Possible Duplicate: c++ virtual function return type I have a simple but confusing question
Possible Duplicate: Can main function call itself in C++? I found this problem very
Possible Duplicate: confusion in scanf() with & operator Why we need a & in
Possible Duplicate: Python list confusion I've got one little question about Python lists: Why
Possible Duplicate: Benefits of inline functions in C++? I have a confusion regarding the

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.