pointers

can someone explain to me this?

int a=3, b=5, v=7;
int *pa=&b, *pb=&c, *pc=&a;

*pa = *pb + *pc;
*pc = *pa * *pb;
pb = pa;
*pb = *pb + *pc;


and what is the output after it is executed?

thank you!
Last edited on
Try running this first.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
int main()
{
int a=3, b=5, c =4, v=7;
int *pa=&b, *pb=&c, *pc=&a;
cout << "int *pa=&b, *pb=&c, *pc=&a;\n";
cout << pa << " " << *pa << " " << " " << pb << " " << *pb << " " << pc << " " << *pc << endl << endl;
*pa = *pb + *pc;
cout << "*pa = *pb + *pc;\n";
cout << pa << " " << *pa << endl<< endl;
*pc = *pa * *pb;
cout << "*pc = *pa * *pb;\n";
cout << pc << " " << *pc << endl<< endl;
pb = pa;
cout << "pb = pa;\n";
cout << pb << " " << *pb << endl<< endl;
*pb = *pb + *pc;
cout << "*pb = *pb + *pc;\n";
cout << pb << " " << *pb << endl<< endl;	

	return 0;
}



Pointers are just simple types that hold hexidecimal addresses. If you reference them without using a * you are referencing the actual hex address and not the value that it is pointing to.

By using the * your are referencing the value it is pointing to.

Last edited on
closed account (4z0M4iN6)
I suggest, you should read a book about C or C++. This would be the normal way of learning a new programming language.
Last edited on
Topic archived. No new replies allowed.