cplusplus.com cplusplus.com
cplusplus.com   C++ : Forums : UNIX/Linux Programming : FUNCTION
  Search:
- -
C++
Information
Documentation
Reference
Articles
Sourcecode
Forums
Forums
Beginners
Windows Programming
UNIX/Linux Programming
General C++ Programming
Articles
Lounge
Jobs

-

question  FUNCTION

detorresrc
please help me, how to create function that will return array charecter....
|
geektoo
why you don't use pointer.
|
detorresrc
can u give example.
|
geektoo
ok, but does your array are created in your function?
|
detorresrc
yes array are created in function and i like to pass to variable...
|
DiptenduDas
Hi ,
Hope the code below may give u some idea.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
#include<iostream>
using namespace std;

int* changeArray()
{
	int* b = new int[5];

	for(int i = 0; i<5;i++)
		b[i]=i+5;

	return b;
}

int main()
{
	int* x=0;

	x=changeArray();

	for(int i = 0; i<5;i++)
		cout<<x[i]<<endl;
	
	delete[] x;

	return 0;
}
|

Registered users can reply in this forum.
Home page | Privacy policy
© cplusplus.com, 2000-2008 - All rights reserved - v2.2
Spotted an error? contact us