473,386 Members | 1,699 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

How to define a function that returns a pointer to an array?

itiger
12
give a sample example of it.
Sep 3 '10 #1

✓ answered by Banfa


5 1510
Something like this ?
Expand|Select|Wrap|Line Numbers
  1. int* getArray();
Sep 3 '10 #2
Banfa
9,065 Expert Mod 8TB
Read this
Sep 3 '10 #3
itiger
12
your function declaration returns pointer to an integer variable not a 'pointer to an int array'.
Sep 3 '10 #4
your function declaration returns pointer to an integer variable not a 'pointer to an int array'.
They are in fact the same, please do click on the link Banfa gave you.
Sep 3 '10 #5
weaknessforcats
9,208 Expert Mod 8TB
They are in fact the same, please do click on the link Banfa gave you.
Not true. An int pointer is not a pointer to an array. An int pointer is a pointer to a single int.

In both C and C++ when you refer to an array by using the address of element 0, you lose the number of elements and end up with only the address of element 0. This is called decay of array and because of this you also need the number of elements.

Also, in C and C++, functions have a return type which can be a) a type or b) a pointer to a type. The most you can return is the address of an element of the array.
Sep 4 '10 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

6
by: | last post by:
Say we have the following code defining TMyMsgHandler and TMyClass typedef void (*TOnMsgReceive) (TMyMessage Msg); class TMyMsgHandler { public: TMyMsgHandler(); virtual ~TMyMsgHandler();...
4
by: Bryan Parkoff | last post by:
I want to allocate pointer array into memory so pointer array contains ten pointers. It would be 4 bytes per pointer to be total 40 bytes. Looks like below for example. unsigned char* A = new...
48
by: yezi | last post by:
Hi, all: I want to record some memory pointer returned from malloc, is possible the code like below? int memo_index; int i,j; char *tmp; for (i=0;i<10;i++){
4
by: octavio | last post by:
Hello members of the comp.lang.c newsgroup. Please I need you help on the following one. Compiling the simple code I'm getting this error message. Why ? Please what's the correct type of the fb...
9
by: shaun | last post by:
Dear all, I realized an error in a previous post, I reproduce it here because I'm still not sure how to solve it: I want to make a templated function which points to one-past-the-end of a...
1
by: yaya | last post by:
question about pointer and array. can we add a 2-D array (**A) with a 1-D array (*B)? both of the array is define as a pointer in the program. where array A is A and B is B how to get call back...
0
by: lov4mu6 | last post by:
Hello, I have a DLL that I've compiled in Visual C++ which I'm referencing in VB .NET The function in the DLL returns a simple structure array. I need to be able to capture this structure...
6
by: Lighter | last post by:
How to read "The lvalue-to-rvalue, array-to-pointer, and function-to- pointer standard conversionsare not applied to the left expressions"? In 5.18 Comma operator of the C++ standard, there is a...
26
by: aruna.mysore | last post by:
Hi all, I have a specific problem passing a function pointer array as a parameter to a function. I am trying to use a function which takes a function pointer array as an argument. I am too sure...
5
by: Immortal Nephi | last post by:
I would like to design an object using class. How can this class contain 10 member functions. Put 10 member functions into member function pointer array. One member function uses switch to call...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.