helpp me m begiineer how pas pointer type array to function

#include<iostream>
#include<conio.h>

using namespace std;

void main()
{
int *temp;
temp=new int[10];
int get(int *temp);
void display(int *temp);



getch();
}

int get(int temp[])
{


for(int i=0;i<10;i++)
{

cin>>temp[i];
}
return *temp;

}

void display(int temp[])
{
for(int i=0;i<10;i++)
{

cout<<temp[i];
}
}
Please, re-post your code with code tags, (you can find it under "Format:" ), and specify your problem.
it is not get values by cin
Last edited on
Then what is it ?
can u tell me what is wrong with it.. i want to knw how to pass array pointer to function
Pass the pointer to the function. You need to declare the function to take a pointer parameter.
Last edited on
how can u write a right code
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
28
29
30
31
32
#include<iostream>
#include<conio.h>
 
using namespace std;

void get( int *temp, int n );
void display( const int *temp, int n );
 
int main()
{
   const int N = 10;
   int *temp;

   temp = new int[N];

   get( temp, N );
   display( temp, N );

   getch();

   return ( 0 );
}
 
void get( int temp[], int n )
{
   for( int  i = 0; i < n; i++ ) cin >> temp[i];
}
 
void display( const int temp[], int n )
{
   for ( int i = 0; i < n; i++ ) cout << temp[i];
} 
Last edited on
Topic archived. No new replies allowed.