In this case, your array variable arr can actually also be treated as a pointer to the beginning of your array’s block in memory, by an implicit conversion. This syntax that you’re using:
int fillarr(int arr[])
Is kind of just syntactic sugar. You could really replace it with this and it would still work:
int fillarr(int* arr)
So in the same sense, what you want to return from your function is actually a pointer to the first element in the array:
int* fillarr(int arr[])
And you’ll still be able to use it just like you would a normal array:
int main()
{
int y[10];
int *a = fillarr(y);
cout << a[0] << endl;
}
Related Posts:
- How do I return a char array from a function?
- C++ correct way to return pointer to array from function
- Is C++ Array passed by reference or by pointer?
- Reverse Contents in Array
- Passing a 2D array to a C++ function
- How to create a dynamically-allocated array of const objects, but have values assigned to them?
- How to make an array with a dynamic size? General usage of dynamic arrays (maybe pointers too)?
- C++: Expression must have a constant value when declaring array inside function
- Delete 2D array C++
- How to return a struct from a function in C++?
- Why can’t we pass arrays to function by value?
- C++ pass an array by reference
- C++ Array of pointers: delete or delete []?
- function does not take 1 arguments c++
- Warning: comparison of distinct pointer types
- Difference between function arguments declared with & and * in C++
- Array of Linked Lists C++
- How to dynamically allocate arrays in C++
- How to dynamically allocate arrays in C++
- What are the differences between a pointer variable and a reference variable in C++?
- How do I find the length of an array?
- C++ — expected primary-expression before ‘ ‘
- Initializing an array of objects
- Passing an array by reference
- What does “dereferencing” a pointer mean?
- Regular cast vs. static_cast vs. dynamic_cast
- What is a smart pointer and when should I use one?
- What does “dereferencing” a pointer mean?
- Meaning of = delete after function declaration
- What is a char*?
- Passing an array by reference
- What exactly is nullptr?
- How to convert a char array to a string?
- How to fix a “invalid operands to binary expression” error?
- What is the array form of ‘delete’?
- Use new operator to initialise an array
- How do I declare a 2d array in C++ using new?
- What is a dangling pointer?
- What does `*&` in a function declaration mean?
- (->) arrow operator and (.) dot operator , class pointer
- lvalue required as left operand of assignment – Array
- What is uintptr_t data type
- What is the difference between const int*, const int * const, and int const *?
- C++ – No matching member function for call to ‘push_back’
- What is uintptr_t data type
- What does int & mean
- What is the difference between const int*, const int * const, and int const *?
- Pointer to incomplete class type is not allowed
- invalid use of non-static member function
- Is there a function to copy an array in C/C++?
- Cleanest way to copy a constant size array in c++11
- C++ error: “Array must be initialized with a brace enclosed initializer”
- warning: ISO C++ forbids variable length array
- c++: No instance of overloaded function
- c++ array – expression must have a constant value
- error: expected primary-expression before ‘)’ token (C)
- Can’t resolve Error: indirection requires pointer operand (‘int’ invalid)
- Static array vs. dynamic array in C++
- How to access the contents of a vector from a pointer to the vector in C++?
- Fill array with random numbers within a specified range (C++)
- Remove an array element and shift the remaining ones
- How to add element to C++ array?
- How to convert vector to array
- How to find the size of an int[]?
- What does int & mean
- splitting a string into an array in C++ without using vector
- What’s the syntax for declaring an array of function pointers without using a separate typedef?
- Printing an array in C++?
- Sorting Linked List C++ with pointers
- error: “initializer expression list treated as compound expression”
- Is the sizeof(some pointer) always equal to four?
- How do you initialise a dynamic array in C++?
- C++ array assign error: invalid array assignment
- C++ Expression must have pointer-to-object type
- C++ strings and pointers
- Getting error: ISO C++ forbids declaration of with no type
- initial value of reference to non-const must be an lvalue
- Typedef function pointer?
- How to initialize a vector of pointers
- What is the use of intptr_t?
- How to add element to C++ array?
- Reading from .txt file into two dimensional array in c++
- extended initializer lists only available with
- Creation of Dynamic Array of Dynamic Objects in C++
- how to initialize an empty integer array in c++
- C++ – Assigning null to a std::string
- Check if C++ Array is Null
- Correct way to work with vector of arrays
- Function for C++ struct
- Resizing dynamic array in c++
- C++ Initializing a Global Array
- Comparing the values of char arrays in C++
- Dynamically allocated string array, then change it’s value?
- c++ –
- error: invalid initialization of non-const reference of type ‘int&’ from an rvalue of type ‘int’
- Using C-string gives Warning: “Address of stack memory associated with local variable returned”
- Reference to non-static member function must be called
- How can I assign an array from an initializer list?
- Why use pointers?
- What does it mean that “a declaration shadows a parameter”?