Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Пример3.Указатели и ссылки:
- //сравнительный анализ
- #include <iostream>
- using namespace std;
- void inc1(int x) {
- ++x;
- }
- void inc2(int & x) {
- ++x;
- }
- void inc3(int * x) {
- ++(*x);
- }
- int main() {
- int x = 10;
- cout << x << " ";
- inc1(x);
- cout << x << " ";
- inc2(x);
- cout << x << " ";
- inc3(&x);
- cout << x << endl;
- cout << x << " " << &x << " " << *&x << endl;
- int & p = x;
- p = 100;
- cout << x << endl;
- int * f = &x;
- *f = 200;
- cout << x << endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment