pointers

hello Ive been trying to learn pointers and Im having a hard time with them, after doing all the exercises from various websites and searching through posts Im still none the wiser really, my little pointer exercise program is not changing the value of an array of struct im sending it.

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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
#include <iostream>
#include <conio.h>

using namespace std;

struct mystruct{
	int number;
	char name;
};

int passmypointer(int p, int l);
void changemyarray(int *pointer, int size);
void changemystruct(int *arraypointer, int size);


int main()
{
	mystruct myarraystruct[10];
	for (int i = 0; i < 10; i++){
		myarraystruct[i].number = i + 1;
		myarraystruct[i].name = 'A';
	}

	for (int i = 0; i < 10; i++)
		cout << myarraystruct[i].number << "  " << myarraystruct[i].name << endl;

	int *myarraypointer;
	myarraypointer = new int[10];
		if (myarraypointer == '\0')
			exit(0);
		else
			for(int i = 0; i < 10; i++)
				myarraypointer[i] = i * i;

		for(int i = 0; i < 10; i++)
			cout << myarraypointer[i] << "  " << &myarraypointer[i] << endl;

	int *p;
	int **l;
	int ***z;
	int n = 2523;
	int v = 450;
	int end = 101011;
	cout << "Address of V : " << &v << endl;
	cout << "Value of n   : " << n << endl;
	cout << "Address of n : " << &n << endl;

	p = &n;

	cout << "Value of *p   : " << *p << endl;
	cout << "Address of p  : " << &p << endl;

	

	l = &p;

	cout << "Value of **l   : " << **l <<endl;
	cout << "Address of l  : " << &l << endl;

	

	cout << "Value after passing  :" << passmypointer(**l, *p) << endl;

	cout << "Value after function :" << **l << endl;

	z = &l;

	cout << "Z = " << ***z << endl;

	int *y;
	y=&v;

	
	cout << "Address of *y :" << &y << endl;

	cout << "Value pointed to by *y :" << *y << endl;

	cout << endl << "Point at something else " << endl << endl;

	p = &end;
	y = &end;
	*l = &end;

	cout << "P = " << *p << " Address = " << &p << endl;
	cout << "Y = " << *y << " Address = " << &y << endl;
	cout << "l = " << **l << " Address = " << &l << endl;

	changemyarray(myarraypointer,10);

	cout << "After passing my array" << endl;
	for(int i = 0; i < 10; i++)
			cout << myarraypointer[i] << "  " << &myarraypointer[i] << endl;

	cout << "After passing my struct" << endl;
	changemystruct(myarraystruct,10);
	for (int i = 0; i < 10; i++)
		cout << myarraystruct[i].number << "  " << myarraystruct[i].name << endl;

	getch();
	return 0;


}

int passmypointer(int p, int l)
{
	return p + l;
}

void changemyarray(int *pointer, int size)
{
	for(int i = 0; i < size; i++)
				pointer[i] = 0;


}

void changemystruct(int *arraypointer, int size)
{
	for(int i = 0; i < size; i++){
				arraypointer[i].number = 0;
				arraypointer[i].name = 'B';
	}
	

}


Error Im getting is

1>------ Build started: Project: pointer, Configuration: Debug Win32 ------
1>Compiling...
1>point.cpp
1>c:\users\mikey\documents\visual studio 2008\projects\pointer\pointer\point.cpp(95) : error C2664: 'changemystruct' : cannot convert parameter 1 from 'mystruct [10]' to 'int *[]'
1> Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
1>c:\users\mikey\documents\visual studio 2008\projects\pointer\pointer\point.cpp(121) : error C2228: left of '.number' must have class/struct/union
1> type is 'int *'
1>c:\users\mikey\documents\visual studio 2008\projects\pointer\pointer\point.cpp(122) : error C2228: left of '.name' must have class/struct/union
1> type is 'int *'

Thank you.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
struct mystruct{
	int number;
	char name;
};

int passmypointer(int p, int l);
void changemyarray(int *pointer, int size);
void changemystruct(int *arraypointer, int size); //<<====  

.....
//skip a lot of stuff here

void changemystruct(int *arraypointer, int size)//<<=====
{
	for(int i = 0; i < size; i++){
				arraypointer[i].number = 0;
				arraypointer[i].name = 'B';
	}
	

}


Check carefully - is int* the correct type for the first parameter ????
A eureka moment, mystruct is my int thanks alot.
Topic archived. No new replies allowed.