passing by pointer

i have this code that was done using pass by reference but i need to change those parts to pass by pointer. I changed some of it but i dont know what else to change. on the functions i changed to a pointer, now the function doesnt recognize the other variables. where am i going wrong
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#include <iostream>
#include <cmath>
using std::cout;
using std::endl;

int Fun1 ( int a, int b );
void Fun2 ( int * A, int b );
void Fun3 ( int * c, int * d );
void PrintOutput( int a, int b );

int main ( )
{
    int a = 2; 
	int b = 10;
	int *A = & a;

    PrintOutput ( a, b );

    a = Fun1 ( a, b );

    cout << a << "\t" << b << endl;

    Fun2 ( A, b );
    PrintOutput ( a, b );

    return 0;
}
// PrintOutput
void PrintOutput ( int a, int b )
{
   cout << a << "\t" << b << endl;
}
// Fun1
int Fun1 ( int a, int b )
{
   int c;

   c = a + b;
   a++;
   --b;

   cout << a << "\t" << b << "\t" << c << endl;
	
   return c;
}
// Fun2
void Fun2 ( int * A, int b )
{
    *A += 5;
    double temp = pow(static_cast<double>(*A), 2);
    b = static_cast<int>( temp ); 

    PrintOutput ( a, b );
    Fun3 ( a, b );
    PrintOutput ( a, b );
}
// Fun3
void Fun3 ( int * c, int * d )
{
    *c = 25;
    *d = 10;
	

    PrintOutput ( c, d );
}
firstly, in Fun2 there is no 'a' declered. I suppose you want to use *A instead. Also, Fun3 takes int* arguments, so that would be Fun3( A,&b ) in line 54. The same thing in line 64. c and d are pointers and you need valuse so use *c and *d.
Last edited on
got it. thanks for ur help
Topic archived. No new replies allowed.